categories removed image find simplified
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from .models import Post, Event, Category, News, FetMeeting
|
from .models import Post, Event, News, FetMeeting
|
||||||
from .forms import MyPostForm, MyEventForm, MyNewsForm, MyFetMeetingForm
|
from .forms import MyPostForm, MyEventForm, MyNewsForm, MyFetMeetingForm
|
||||||
|
|
||||||
import django.contrib.auth.admin
|
import django.contrib.auth.admin
|
||||||
@@ -13,9 +13,6 @@ import taggit.admin
|
|||||||
|
|
||||||
admin.site.unregister(taggit.models.Tag)
|
admin.site.unregister(taggit.models.Tag)
|
||||||
|
|
||||||
class MyCategoryAdmin(admin.ModelAdmin):
|
|
||||||
model = Category
|
|
||||||
admin.site.register(Category,MyCategoryAdmin)
|
|
||||||
|
|
||||||
class MyPostAdmin(admin.ModelAdmin):
|
class MyPostAdmin(admin.ModelAdmin):
|
||||||
form = MyPostForm
|
form = MyPostForm
|
||||||
|
|||||||
@@ -122,14 +122,15 @@ class Post(models.Model):
|
|||||||
|
|
||||||
def find_an_image(self):
|
def find_an_image(self):
|
||||||
"find an image via another post"
|
"find an image via another post"
|
||||||
|
#ToDo: Explain why this image is selected on save of the image
|
||||||
posts1=Post.objects.filter(slug__in=self.tags.names()).filter(image__isnull=False)[0:1].all() # Query all posts that have a slug that equals one of the tags
|
posts1=Post.objects.filter(slug__in=self.tags.names()).filter(image__isnull=False)[0:1].all() # Query all posts that have a slug that equals one of the tags
|
||||||
if len(posts1)>0:
|
if len(posts1)>0:
|
||||||
return posts1.get().image
|
return posts1.get().image
|
||||||
|
|
||||||
posts2=self.tags.similar_objects()
|
#posts2=self.tags.similar_objects()
|
||||||
for p in posts2:
|
#for p in posts2:
|
||||||
if p.image is not None:
|
# if p.image is not None:
|
||||||
return p.image
|
# return p.image
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user