मुझे Django के साथ बनाया गया एक ऐप विरासत में मिला है। इसमें कोई समस्या है: व्यवस्थापक इंटरफ़ेस में, पृष्ठ सभी इकाइयों (वीडियो) को सूचीबद्ध नहीं करता है, लेकिन कुछ (25 में से 16)। मुझे नहीं पता, यह क्या है।Django व्यवस्थापक सभी इकाइयों को दिखाता नहीं है
तब मैं python manage.py shell
चलाने के लिए, और वहाँ Video.objects.all()
, वहाँ सभी 25 वस्तुओं (len
का उपयोग कर उन्हें गिना जाता है और उन्हें for
पाश के साथ पुनरावृत्ति द्वारा) कर रहे हैं।
मुझे कोई प्रबंधक या जो कुछ भी मिला है (शायद मुझे नहीं पता कि उन्हें कहां देखना है)।
व्यवस्थापक पृष्ठ के नीचे: 25 videos
, जबकि केवल 16 पंक्तियां हैं।
फिर मैं VideoModelAdmin वर्ग list_per_page = 10
में जोड़ता हूं, पेजिनेटर तीन पेज दिखाता है, लेकिन उनमें से केवल पहले दो में कोई वीडियो है, तीसरा कोई पंक्ति नहीं दिखाता है।
यहां कुछ कोड दिए गए हैं।
# admin.py
class VideoModelAdmin(admin.ModelAdmin):
list_display = ['title', 'short_desc', 'author', 'redactor_choise', 'views_num', 'rating', 'is_published']
list_filter = ['is_published', 'redactor_choise']
list_per_page = 10
actions = ['make_published', 'update_comments_count']
exclude = ('file_lq', 'file_hq',)#'thumb',)
def make_published(self, request, queryset):
queryset.update(is_published=1)
make_published.short_description = "Опубликовать выделенные"
def save_model(self, request, obj, form, change):
instance = form.save(commit=False)
instance.author = request.user
instance.save()
return instance
def update_comments_count(self, request, queryset):
for video in queryset:
video.update_comments_count()
update_comments_count.short_description = "Пересчитать комментарии!"
# later there
admin.site.register(Video, VideoModelAdmin)
# models.py
class Video(models.Model):
def make_upload_path(instance, filename):
return 'video/thumbs/' + generate_random_name(filename)
category = models.ManyToManyField(Category, limit_choices_to = {'is_published': 1})
title = models.CharField(max_length=128)
short_desc = models.CharField(max_length=255)
long_desc = tinymce_models.HTMLField(blank=True)
file_lq = models.FileField(upload_to='video/lq/', null=True, blank=True)
file_hq = models.FileField(upload_to='video/hq/', null=True, blank=True)
thumb = models.FileField(upload_to=make_upload_path, blank=True, null=True)
#thumb = fields.ThumbnailField(upload_to=make_upload_path, sizes=settings.VIDEO_THUMB_SIZE, blank=True, null=True)
author = models.ForeignKey(User, editable=False)
redactor_choise = models.BooleanField(default=False)
views_num = models.SmallIntegerField(default=0, editable=False)
comments_num = models.SmallIntegerField(default=0, editable=False)
rating = models.SmallIntegerField(default=0, editable=False)
voters = fields.PickledObjectField(blank=True, editable=False)
created = models.DateTimeField(auto_now_add=True)
is_published = models.BooleanField(default=False)
def get_absolute_url(self):
return "/video/%d" % self.id
def views_num_plus(self):
cursor = connection.cursor()
cursor.execute('update soctv_video set views_num=views_num+1 where id=%d', [self.id])
cursor.close()
def update_comments_count(self):
from threadedcomments.models import ThreadedComment as Comment
self.comments_num = Comment.objects.filter(video=self).count()
self.save()
#cursor = connection.cursor()
#cursor.execute('update soctv_video set comments_num = (select count(*) from soctv_comment where video_id = %s) where id = %s', [self.id, self.id])
#cursor.close()
def update_categories_counts(self):
cursor = connection.cursor()
cursor.execute('update soctv_category set num_items = (select count(*) from soctv_video_category where category_id = soctv_category.id)')
cursor.close()
def is_user_voted(self, uid):
try:
if self.voters[uid]:
return self.voters[uid]
except Exception:
return False
def increment_view_count(self, token):
import md5
token = md5.new(token).hexdigest()
if VideoView.objects.filter(uniquetoken=token).count() == 0:
VideoView(uniquetoken = token, video = self).save()
def view_count(self):
return self.views_num + VideoView.objects.filter(video=self).count()
def __unicode__(self):
return unicode(self.title)
ओह संशोधित करने की अनुमति नहीं थी। धन्यवाद। समझा। क्या मैं हाथों से कंसोल में एफके बदलने के अलावा कुछ कर सकता हूं? –
धन्यवाद, मेरे पास Video.objects.all(): में है ... i.author = adm ... i.save() ने मुझे बचाया :) –