Awesome.  Thanks for clearing that up for me.

On Apr 22, 4:12 pm, Michael <[EMAIL PROTECTED]> wrote:
> Thanks. It was something in your models.
>
> Django can't just magically figure out what url you want besed on the same
> function. Look at the way that you return the get_absolute_url:
>
> def get_absolute_url(self):
>     return ('django.views.generic.list_detail.object_detail', (), { 'slug':
> self.slug, })
>
> This function is the EXACT same as the one in your precincts models. How is
> Django supposed to know which is which.
>
> You need to somehow differentiate the names of your url conf. So you can in
> your urls name the url like:
>
> urlpatterns += patterns('django.views.generic.list_detail',
>    (r'(?P<slug>[\w-]+)/$', 'object_detail', election_detail_info,
> 'election_detail'),
> )
>
> and then in your election models:
> def get_absolute_url(self):
>     return ('election_detail', (), { 'slug': self.slug, })
>
> 2008/4/22 jeffself <[EMAIL PROTECTED]>:
>
>
>
> > Here's the elections model:
> > class Election(models.Model):
> >    uuid = UUIDField(primary_key=True, editable=False)
> >    election_name = models.CharField(max_length=100, unique=True)
> >    slug = models.SlugField(prepopulate_from=("election_name",),
> > unique=True)
> >    election_date = models.DateField()
>
> >    class Meta:
> >        ordering = ('-election_date',)
>
> >    class Admin:
> >        list_display = ('election_name', 'election_date')
> >        list_per_page = 20
>
> >    def __unicode__(self):
> >        return self.election_name
>
> >    def get_absolute_url(self):
> >        return ('django.views.generic.list_detail.object_detail', (),
> >                { 'slug': self.slug, })
> >    get_absolute_url = permalink(get_absolute_url)
>
> > Here's the precincts model:
> > class Precinct(models.Model):
> >    precinct_number = models.CharField(max_length=4, blank=True)
> >    precinct_name = models.CharField(max_length=100)
> >    slug =
> > models.SlugField(prepopulate_from=("precinct_number","precinct_name",),)
> >    precinct_location = models.CharField(max_length=100)
> >    precinct_address = models.CharField(max_length=100)
> >    precinct_photo = models.ImageField(upload_to="images/
> > precincts",blank=True)
> >    precinct_map = models.ImageField(upload_to="images/precincts/
> > maps",blank=True)
> >    precinct_status = models.BooleanField("Active",default=True)
>
> >    class Meta:
> >        ordering = ('precinct_number',)
> >        unique_together = [("precinct_number", "precinct_name")]
>
> >    class Admin:
> >        list_display =
> > ('precinct_number','precinct_name','precinct_status')
> >        list_display_links = ('precinct_number', 'precinct_name')
> >        list_filter = ('precinct_status',)
> >        list_per_page = 20
> >        search_fields =
> > ('precinct_name','precinct_location','precinct_address')
> >        fields = (
> >            (None, {
> >                'fields': (('precinct_number', 'precinct_name'),
> > 'slug', 'precinct_location',
> >                           'precinct_address', 'precinct_status')
> >                }),
> >                ('Media', {
> >                    'classes': 'collapse',
> >                    'fields': ('precinct_photo','precinct_map')
> >                })
> >        )
>
> >    def __unicode__(self):
> >        return '%s %s' % (self.precinct_number, self.precinct_name)
>
> >    def get_absolute_url(self):
> >        return ('django.views.generic.list_detail.object_detail', (),
> >                { 'slug': self.slug, })
> >    get_absolute_url = permalink(get_absolute_url)
>
> > On Apr 21, 9:39 pm, Michael <[EMAIL PROTECTED]> wrote:
> > > You interested in answering the first part of my post? I can't really
> > help
> > > you with information like this...
>
> > > 2008/4/21 jeffself <[EMAIL PROTECTED]>:
>
> > > > I don't think thats it because if I reverse the order of the url's in
> > > > the root urls.py file and put precincts before elections, then
> > > > precincts items work correctly but the election items point to
> > > > precincts rather than elections.
>
> > > > On Apr 21, 3:52 pm, Michael <[EMAIL PROTECTED]> wrote:
> > > > > How are you getting the URL? Is there something in your models that
> > is
> > > > > defining the absolute URL? or are you using the Revese lookup?
>
> > > > > Chances are because they are just copies of one another that you
> > forgot
> > > > to
> > > > > change one of the files and they still have the get_absolute_url
> > > > referring
> > > > > to the elections one,
>
> > > > > Michael
>
> > > > > On Mon, Apr 21, 2008 at 12:48 PM, 小龙 <[EMAIL PROTECTED]> wrote:
> > > > > > Show  me ------ Settings.py
>
> > > > > > 2008/4/21, jeffself <[EMAIL PROTECTED]>:
>
> > > > > > > I've got a project that contains two apps (elections and
> > precincts).
> > > > > > > My root urls.py looks like this:
> > > > > > > from django.conf.urls.defaults import *
> > > > > > > urlpatterns = patterns('',
> > > > > > >     (r'^elections/', include('elections.urls')),
> > > > > > >     (r'^precincts/', include('precincts.urls')),
> > > > > > >     (r'^admin/', include('django.contrib.admin.urls')),
> > > > > > > )
>
> > > > > > > My elections urls.py looks like this:
> > > > > > > from django.conf.urls.defaults import *
> > > > > > > from elections.models import Election
> > > > > > > from django.views.generic import list_detail
> > > > > > > election_list_info = {
> > > > > > >     'queryset': Election.objects.all(),
> > > > > > >     'allow_empty': True,
> > > > > > > }
> > > > > > > election_detail_info = {
> > > > > > >     "queryset" : Election.objects.all(),
> > > > > > >     "template_object_name" : "election",
> > > > > > > }
> > > > > > > urlpatterns = patterns('',
> > > > > > >     (r'^$', list_detail.object_list, election_list_info),
> > > > > > > )
> > > > > > > urlpatterns += patterns('django.views.generic.list_detail',
> > > > > > >     (r'(?P<slug>[\w-]+)/$', 'object_detail',
> > election_detail_info),
> > > > > > > )
>
> > > > > > > Each item on the elections page works correctly and has the
> > correct
> > > > > > > URL.
>
> > > > > > > My precincts urls.py file looks identical to the elections
> > urls.py
> > > > > > > file except it imports the precincts model and I changed the
> > code
> > > > from
> > > > > > > election to precinct where necessary.  I can bring up the
> > Precincts
> > > > > > > page but the items on the page have the wrong url.  Instead of
> > > > having
> > > > > > > a url likehttp://localhost:8000/precincts/0001, the url looks
> > like
> > > > > > >http://localhost:8000/elections/0001.  I can see that its looking
> > > > back
> > > > > > > at the root urls.py first and chooses the elections pattern.
> >  But
> > > > why
> > > > > > > is this?
>
> > > > > > > What do I need to change to make it look at precincts instead of
> > > > > > > elections?  I need to understand this so I can continue to
> > separate
> > > > my
> > > > > > > program into separate apps as much as possible.  Thanks!
>
> > > > > > --
> > > > > > deSign thE  fuTure
> > > > > >http://www.freeis.cn/
--~--~---------~--~----~------------~-------~--~----~
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