Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango URL configuration
    text
    copied!<p>Assume I have 3 Models: City, Area, Entry.</p> <p>Each city has several Areas and each area can have several entries BUT for "now", there can be will be only one active Entry and it will be shown. So in logic:</p> <p>Note that each city, area, entry will be using slug variable of related model class</p> <p>Format will be in such:</p> <pre><code>www.mysite.com/&lt;slug of city&gt;/&lt;slug of area&gt;/&lt;slug of entry&gt; </code></pre> <p><code>www.mysite.com/mycity/myarea/</code> -> will be displaying an Entry that is bound to that Area AND active (this can be detected by using Area's <code>active_entry</code> function).</p> <p>But users can view some old Entries such as:</p> <p><code>www.mysite.com/mycity/myarea/some-old-entry-that-is-no-longer-active</code></p> <p>I have written get_absolute_url functions by reading the "Practical Django Projects 2nd Edition" book but now I am stucked.</p> <p>I have such models:</p> <pre><code>from django.db import models class Entry(models.Model): area = models.ForeignKey('Area',verbose_name="The area that this entry belongs to") slug = slug = models.SlugField(unique=True) # this will be auto populated via admin panel, from title title = baslik = models.CharField() content = models.TextField() start_time = models.DateTimeField()#start time for this entry. end_time = models.DateTimeField()#end time for this entry. @models.permalink def get_absolute_url(self): return ("entry.detail",(),{"city":self.area.city.slug,"area":self.area.slug,"entry":self.slug}) class Area(models.Model): city = models.ForeignKey(verbose_name="city that this area belongs to") name = models.CharField(max_length=30) slug = models.SlugField(unique=True)# this will be auto populated via admin panel, from name @models.permalink def get_absolute_url(self): return ("bolge.detay",(),{"city":self.city.slug,"area":self.slug}) def active_entry(self): from datetime import datetime, date, time now = datetime.now() try: return Entry.objects.get(area__exact=self,start_time__lte=now,end_time__gte=now) except Entry.DoesNotExist: return False class City(models.Model): name =models.CharField(max_length=30) slug = models.SlugField(unique=True) # this will be auto populated via admin panel, from name @models.permalink def get_absolute_url(self): return ("city.detail",(),{"city":self.slug}) </code></pre> <p>Please help this poor soul to configure his url configuration.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload