I have a inline form which looks like the snapshot above but when I save
the "Cinema, Movie type and Price" doesn't get added to the additional
fields (each starts time is another instance of the field). For example the
second line with 2015-10-02 Cinema2 will only be saved on the instance of
Show 11:00so it only saves on the first instance.
This is the model Show:
class Show(models.Model):
MOVIE_TYPES = (
('2', '2D'),
('3', '3D'),
)
CINEMAS = (
('C1', 'Cinema 1'),
('C2', 'Cinema 2'),
('C3', 'Cinema 3'),
('C4', 'Cinema 4'),
)
movie = models.ForeignKey('Movie', related_name='shows')
venue = models.ForeignKey(Venue)
old_details = models.TextField(blank=True, editable=False,)
starts = models.DateField(db_index=True,)
starts_time = models.TimeField(db_index=True,)
couple_price = models.IntegerField(blank=True, null=True)
vip = models.IntegerField(blank=True, null=True)
cinema = models.CharField(
max_length=10,
choices=CINEMAS,
blank=True,
null=True
)
comment = models.TextField(blank=True, )
booking_url = models.URLField(blank=True, )
created = models.DateTimeField(editable=False, db_index=True,)
modified = models.DateTimeField(editable=False, db_index=True,)
price = models.IntegerField(blank=True, null=True)
new_price = models.IntegerField(blank=True, null=True)
movie_type = models.CharField(
max_length=1,
choices=MOVIE_TYPES,
blank=True,
null=True
)
class Meta:
ordering = ['starts', 'starts_time',]
verbose_name = 'movie show'
def __unicode__(self):
return u'%s - %s - %s %s' % (self.movie.name, self.venue.name,
self.starts, self.starts_time)
def save(self):
if not self.id:
self.created = datetime.datetime.now()
self.modified = datetime.datetime.now()
super(Show, self).save()
def movie_type_str(self):
if not self.movie_type:
return '-'
else:
return self.movie_type + 'D'
and the form...
class ShowInlineForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ShowInlineForm, self).__init__(*args, **kwargs)
theatres = Category.objects.get(slug='movie-theatres')
self.fields['venue'].queryset =
Venue.objects.filter(categories=theatres, visible=True,).order_by('name')
class Meta:
fields = [
'venue',
'price',
'movie_type',
'starts',
'cinema',
'starts_time',
]
in the admin.py
class MovieShowInline(admin.TabularInline):
formfield_overrides = {
models.TimeField: {'widget': AdminTimeWidget(format='%H:%M')},
models.TextField: {'widget': TextInput()},
}
model = Show
extra = 1
template = 'admin/movies/show/inline_edit/tabular.html'
form = ShowInlineForm
exclude = ('comment', 'booking_url',)
def queryset(self, request):
"""Do not show shows older than today """
qs = super(MovieShowInline, self).queryset(request)
return
qs.filter(starts__gte=datetime.date.today()).order_by('venue__name', 'starts',
'starts_time')
class MovieShowAdmin(CommonAdmin):
fields = ('name',)
readonly_fields = ('name',)
list_display = [
'name',
'modified_by',
'created_by',
'modified',
'created',
'visible',
]
inlines = [MovieShowInline,]
list_filter = ['modified', 'created', 'visible', 'showing']
and the form admin/movies/show/inline_edit/tabular.html
{% load i18n admin_static admin_modify %}.vTimeField { width:40px
!important; }
{{ inline_admin_formset.formset.management_form }}
{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}
{{ inline_admin_formset.formset.non_form_errors }}
{% for field in inline_admin_formset.fields %}
{% if not field.widget.is_hidden %}
{{ field.label|capfirst }}
{% if field.help_text %}{% endif %}
{% endif %}
{% endfor %}
{% trans "Copy?" %}
{% comment %}
{% if inline_admin_formset.formset.can_delete %}{% trans "Delete?"
%}{% endif %}
{% endcomment %}
{% for inline_admin_form in inline_admin_formset %}
{% if inline_admin_form.form.non_field_errors %}
{{
inline_admin_form.form.non_field_errors }}
{% endif %}
{% if inline_admin_form.has_auto_field %}{{
inline_admin_form.pk_field.field }}{% endif %}
{{ inline_admin_form.fk_field.field }}
{% spaceless %}
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
--
You received this message because you are subscribed to the Google Groups
"Django users"
2 matches
Mail list logo
|