django class-based views key word -
i've been following manual generic views django 1.4, can 'list books publisher' example work. site different in i'm trying list bookings of property name (or id) of person books property. people book more once, want able see bookings were.
my views.url is:
class guestbookinglistview(detailview): context_object_name = 'guest_booking' template_name = 'guest_booking.html' def get_queryset(self): self.guest = get_object_or_404(guest) return booking.objects.filter(guest = self.guest) def get_context_data(self, **kwargs): context = super(guestbookinglistview, self).get_context_data(**kwargs) context['guest'] = self.guest return context
my model is:
class guest(models.model): first_name = models.charfield(max_length=30) last_name = models.charfield(max_length=50) spouse_first = models.charfield(max_length=30, blank=true) spouse_last = models.charfield(max_length=50, blank=true) num_child = models.integerfield(verbose_name='number of children') address = models.textfield(max_length=50, blank=true) city = models.charfield(max_length=60, blank=true, verbose_name='town / city') state_province = models.charfield(max_length=30, blank=true, verbose_name='county') post_code = models.charfield(max_length=8, blank=true) country = models.charfield(max_length=50, blank=true) email = models.emailfield(blank=true) landline = models.charfield(max_length=25, blank=true) mobile = models.charfield(max_length=25, blank=true) def __unicode__(self): return u'%s %s' % (self.first_name, self.last_name) class booking(models.model): guest = models.foreignkey(guest) ack_date = models.datefield(verbose_name='date acknowledged') start_date = models.datefield(verbose_name='start date') end_date = models.datefield(verbose_name='end date') dep_recd = models.datefield(null=true, blank=true, verbose_name='deposit received') bal_recd = models.datefield(null=true, blank=true, verbose_name='balance received') keys_sent = models.datefield(null=true, blank=true, verbose_name='date keys sent') sec_retn = models.datefield(null=true, blank=true, verbose_name='security deposit returned') rtm_sent = models.integerfield('status', blank=true) notes = models.textfield(blank=true, verbose_name='notes')
and urls.py is:
url(r'^guests/(?p<pk>\d+)/$', guestbookinglistview.as_view ( #context_object_name = 'booking_list', )),
so far can see identical (with different field names) example, result is:
get() returned more 1 guest -- returned 26! lookup parameters {}
the 'get' retrieving of guests in database, not 1 i've selected.
i've spent hours of searching , experimenting on this, no avail. if put 'guest = 11' works, there's wrong pk.
thank you!
you haven't given sort of criteria guest. you've said, in effect, "give me guest", , django has given 26 of them. if want filter pk
kwarg, should so:
self.guest = get_object_or_404(guest, pk=self.kwargs['pk'])
Comments
Post a Comment