OK. So does the following code look like it would work the way that we
have been discussing?

from django.db import models
from django.contrib.auth.models import User

# Create your models here.

MINISTRY_CHOICES = (
                    ('MUS', 'music'),
                    ('SIN', 'singles'),
                    ('STU', 'students'),
                    )

class Tag(models.Model):
    tag = models.CharField(maxlength=255, core=True)

    class Admin:
        list_display = ('tag',)

    def __str__(self):
        return self.tag

    def get_absolute_url(self):
        return '/tag/%s/' % (self.tag)

class Entry(models.Model):
    pub_date = models.DateField(db_index=True)
    pub_time = models.TimeField()
    title = models.CharField(maxlength=255)
    slug = models.SlugField(unique_for_date='pub_date',
prepopulate_from=('title',),
                            help_text='Automatically built from the
headline.')
    summary = models.TextField(help_text="Use Markdown")
    body = models.TextField(help_text="Use Markdown")
    ministry = models.CharField(maxlength=3,choices=MINISTRY_CHOICES)
    active = models.BooleanField(default=True)
    user = models.ForeignKey(User, blank=True)
    tags = models.ManyToManyField(Tag, blank=True)
    related_entries = models.ManyToManyField("self", blank=True,
symmetrical=False)

    class Admin:
        list_display = ('slug', 'title', 'pub_date')

    class Meta:
        get_latest_by = "pub_date"
        ordering = ['-pub_date']
        verbose_name_plural = "entries"

    def __str__(self):
        return self.headline

    def get_absolute_url(self):
        return '/%s/%s/' % (self.pub_date.strftime('%Y/%b/%d'),
self.slug)

    def get_tags(self):
        return self.tags.all()

    def get_related_entries(self):
        return self.related_entries.all()

It almost seems that I could do away with the MINISTRY_CHOICES piece
and just use the tags because if a tag name does not already exist the
admin interface will allow one to be created from the Entries page. If
that is the case then if I want a page to only display the posts for
music (assuming that the tag exists) then I just need to do a filter
for it in the view. Is that correct?

Thanks again for all of the help so far. It is very appreciated.

ps. The code above is not my own. I am reusing code from 23excuses.com
and also some from fallingbullets.com.

On Dec 1, 11:17 am, "Eric Lake" <[EMAIL PROTECTED]> wrote:
> Thanks for the comments. I am still in a planning phase and new to
> django as well. I will have to wrap my head around the tag stuff but
> these are great ideas.
>
> On Dec 1, 11:13 am, "Guillermo Fernandez Castellanos"
>
> <[EMAIL PROTECTED]> wrote:
> > > Thank you. That is what I was thinking but I wanted to get others
> > > opinions first. This will also help stay with the DRY ideals. I guess
> > > the real difficult part would be if a new ministry is added to the
> > > list. If I understand how it works I would have to make changes in the
> > > model and then modify the database manually.No, you wouldn't have to 
> > > modify the database manually.
> > You would simply edit the code and add a line. Say:
> > MINISTRY_CHOICES = (
> >                          ('MUS', 'music'),
> >                          ('SIN', 'singles'),
> >                          ('STU', 'students'),
> >                          ('NEW', 'new ministry'),
> >                         )
> > and that would work.
>
> > But, with what you said, I would also recommend tags, as Chris said.
>
> > Make a ministry model:
> > class Ministry(models.Model):
> >     title = models.CharField(maxlength=79)
>
> > and then a 1 to many field:
> > ministry = models.ManyToManyField(Ministry,related_name='post_ministries')
> 
> > G


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to