A fried of mine told me the answer, couldn't find it anywhere online.
Is this documented anywhere?
In my document model I had to add this to order the document list in
the publication admin page
class Meta:
ordering = ('title',)
I was under the impression all the Meta stuff had been moved into
admin.py, obviously not :-)
matt
On Feb 11, 8:04 am, vanderkerkoff <[email protected]> wrote:
> django1.2.4
>
> I've got a document model
>
> class Document(models.Model):
> LANG_CODE = (
> ('B', 'Both'),
> ('E', 'English'),
> ('C', 'Cymraeg'),
> )
> title = models.CharField(max_length=100)
> slug = models.SlugField(max_length=100,
> unique_for_date='created_at')
> created_at = models.DateTimeField('Date Published',
> default=datetime.now, editable=False)
> the_file = models.FileField(upload_to='files/documents/%Y-%m-%d/')
> lang_code = models.CharField(max_length=1, choices=LANG_CODE,
> default='B')
>
> def __unicode__(self):
> return u'%s' % self.title
>
> def get_absolute_url(self):
> url = u'/media/%s' % (self.the_file)
> return iri_to_uri(url)
>
> with a corresponding admin.py
>
> class DocumentAdmin(admin.ModelAdmin):
> fields = ('title','slug','the_file','lang_code')
> list_display = ('title',)
> search_fields = ('title',)
> prepopulated_fields = { 'slug': ('title',) }
> ordering = ('title',)
> admin.site.register(Document, DocumentAdmin)
>
> I've also got a Publications model, in which I can add Documents to a
> publication
>
> class Publication(models.Model):
> title = models.CharField(max_length=255)
> slug = models.SlugField(max_length=255, unique_for_date='pub_date')
> title_c = models.CharField('Welsh Title', max_length=255)
> slug_c = models.SlugField('Welsh Slug', max_length=255,
> unique_for_date='pub_date')
> created_at = models.DateTimeField('Date Published',
> default=datetime.now, editable=False)
> amended_at = models.DateTimeField('Date Modified', blank=True,
> null=True)
> pub_date = models.DateField('Publish Date')
> body = models.TextField(help_text='Body')
> body_html = models.TextField(blank=True, null=True)
> body_c = models.TextField('Welsh Body', help_text='body_c')
> body_c_html = models.TextField(blank=True, null=True)
> the_file = models.FileField('Document', upload_to='files/documents/%Y-
> %m-%d/', blank=True, null=True)
> the_file_c = models.FileField('Welsh Document', upload_to='files/
> documents/%Y-%m-%d/', blank=True, null=True)
> tags = models.CharField(max_length=255, blank=True, null=True)
> tags_c = models.CharField('Welsh tags', max_length=255, blank=True,
> null=True)
> image = models.ForeignKey(Photo,
> limit_choices_to={'category__exact':'P'}, blank=True, null=True)
> category = models.ForeignKey(Category, blank=True, null=True)
> comments = models.BooleanField('Allow Comments', default=False)
> documents = models.ManyToManyField(Document, related_name='pub_doc',
> limit_choices_to = {'lang_code__in': ('B', 'E')}, blank=True,
> null=True)
> documents_c = models.ManyToManyField(Document, verbose_name="Welsh
> Documents", related_name='pub_doc_c', limit_choices_to =
> {'lang_code__in': ('B', 'C')}, blank=True, null=True)
>
> Here's the admin.py of the publicaitons
>
> class PublicationAdmin(admin.ModelAdmin):
> fieldsets = (
> (None, {'fields':
> ('title','slug','title_c','slug_c','category','pub_date','body','body_c','c
> omments','image','documents','documents_c')}),
> ('Advanced options', {'classes': 'collapse', 'fields':
> ('tags','tags_c')}),
> )
> list_display = ('title','id','pub_date')
> list_filter = ('pub_date','category')
> search_fields = ('title','title_c')
> prepopulated_fields = { 'slug': ('title',), 'slug_c': ('title_c',), }
> ordering = ('title',)
> date_hierarchy = 'pub_date'
>
> When I'm in the admin backed and I'm adding a document to a
> Publication, by selecting it from the box that displays the Documents
> that you can add, I want to order of that List of Documents shown in
> the box. I keep thinking I should be putting the ordering in the
> ManyToManyField block in the documents description in the Publication
> model, but I can't find a way to do that, so I'm starting to think
> there is another solution.
>
> Any help, as always, greatly appreciated.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.