Hello List,
I am having problems getting the forms within a modelformset to display
as I wish. I'm using
Django 1.1 with python 2.6.
The model class is:
class Availability(DefaultColumns):
"""Record analyst availability."""
date = django.db.models.ForeignKey(WorkShift)
analyst = django.db.models.ForeignKey(Analyst)
status = django.db.models.ForeignKey(AvailabilityStatus)
(DefaultColumns inherits from django.db.models.Model)
This is the WorkShift model referenced in "date":
class WorkShift(DefaultColumns):
"""A shift as originally generated."""
rota = django.db.models.ForeignKey(WorkRota)
date = django.db.models.DateField()
shift_type = django.db.models.ForeignKey(ShiftType)
def __unicode__(self):
return u'<WorkShift: %s: %s>' % (self.date, self.shift_type)
class Meta:
"""Internal class."""
ordering = ['date']
The form used by the formset looks like this:
class AvailabilityForm(django.forms.ModelForm):
"""ModelForm for Availability model."""
status = django.forms.ModelChoiceField(
queryset=rota.models.AvailabilityStatus.objects.all(),
empty_label=None,
widget=django.forms.RadioSelect)
def __init__(self, *args, **kwargs):
django.forms.ModelForm.__init__(self, *args, **kwargs)
self.logger = logging.getLogger('rota.forms.AvailabilityForm')
self.logger.debug('Initialisation complete.')
class Meta:
"""Meta class."""
model = rota.models.Availability
I want the form to display the date as a read-only field, however so far
I
can't make this work. The code here outputs the date as a selectable
ModelChoiceField. If I declare date in the ModelForm class I always end
up
with the id from the WorkShift object rather than the date itself.
Can you advise how I can declare date (or do something else) to make this
work as I'd like?
Many thanks,
Kev
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
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.