Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Using class based views to autoassign certain values? [RSS Feed]

#1 Jan. 17, 2011 21:09:38

S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Using class based views to autoassign certain values?


When I try to add new Attendee with a class based view I get the error
matriculation_attendee.event_id may not be NULL with this code:

class Event(models.Model):
""" Model representing an event """
place = models.ForeignKey(Place, blank=True, null=True)
slug = AutoSlugField(populate_from=('company', 'name'))
name = models.CharField(max_length=200)
company = models.ForeignKey(Company)
description = models.TextField(null=True, blank=True)
start_date = models.DateField()
end_date = models.DateField()
status = models.CharField(max_length=200, null=False, blank=True)
currency = models.CharField(max_length=4,
choices=currency_choices)
payment_gateway = models.ForeignKey(PaymentGateway, blank=True,
null=True)

def registered(self):
return self.attendee_set.count()

def active(self):
return self.attendee_set.filter(is_active=True).count()

def cancelled(self):
return self.attendee_set.filter(is_active=False).count()

def __unicode__(self):
return self.name

class Meta:
ordering =

def save(self, *args, **kwargs):
if self.end_date < datetime.now().date():
self.status = 'Closed'
elif datetime.now().date() >= self.start_date:
self.status = 'Onsite'
else:
self.status = 'Active'

super(Event, self).save(*args, **kwargs)

class Attendee(CommonDataInfo):
#TODO: Add prefix and suffix choices
event = models.ForeignKey(Event)
prefix = models.CharField(max_length=300, blank=True, null=True)
first_name = models.CharField(max_length=300)
last_name = models.CharField(max_length=300)
suffix = models.CharField(max_length=300, blank=True, null=True)
badge_name = models.CharField(max_length=300, blank=True,
null=True)
birthdate = models.DateField(blank=True, null=True)
reg_date = models.DateTimeField(default=datetime.now())
email = models.CharField(max_length=300, blank=True, null=True)
gender = models.CharField(max_length=1, choices=gender_choices,
blank=True,
null=True)
location = models.ForeignKey(Place, blank=True, null=True)

def __unicode__(self):
return "%s %s" % (self.first_name, self.last_name)

class Meta:
ordering =


class EventContextMixIn(object):
def get_context_data(self, **kwargs):
event = get_object_or_404(Event,
slug=self.kwargs)
# Call the base implementation first to get a context
context = super(EventContextMixIn,
self).get_context_data(**kwargs)
context = event
return context

def get_form_kwargs(self, **kwargs):
context = self.get_context_data()
kwargs = super(EventContextMixIn,
self).get_form_kwargs(**kwargs)
kwargs = context
return kwargs


class EventCreateView(EventContextMixIn, CreateView):
pass


class EventUpdateView(EventContextMixIn, UpdateView):
pass


class EventListView(EventContextMixIn, ListView):
context_object_name = "model_list"


class EventDetailView(EventContextMixIn, DetailView):
context_object_name = 'model'


url(r'^events/(?P<event_id>+)/attendees/add/$',
EventCreateView.as_view(form_class=AttendeeForm,
template_name='matriculation/attendee_update.html'),
name='matriculation_attendees_add'),


Am I using this wrong? I'm basically trying to set this up so I the
url defines the event and then I can create models for the specific
event.

--
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
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Using class based views to autoassign certain values? [RSS Feed]

Board footer

Moderator control

Enjoy the 11th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support