Your first question about how to separate fields is not perfectly
clear to me. However, I can say that I typically put *all* fields on
the actual admin objects, since an admin is typically not the one
you're trying to restrict. Then, in your own custom views (and the
forms you render in those views), you just include the items that you
want to be publicly visible.
> But as far as I understand it this only works on the
> admin page and not generally.
You are correct. Notice how you're setting the "max_num" attribute on
your subclassed ModelAdmin. The Admin is really just an app, though
bundled with Django. Anything you do with the admin won't ever have a
Django- or site-wide impact. That might seem frustrating, but it does
help a lot for people who write general apps, which they distribute to
others. We would find it far *more* frustrating to have to deal with
site-wide side effects that only were intended for the admin site.
The actual solution, since you seem to want to make your own forms and
not use the admin, would be to code this maximum-of-8 logic into your
views. When you render the form, you'll want to do one of two things.
1) If you think you want to just hard code this, just copy and paste
your template HTML to a total of 8 times, so that your form will
appear that many times. You'll of course want to take care to use
proper HTML "name" attributes on the various elements, so that each of
the 8 forms has unique values there. Point blank, you need the 8
forms to have unique names so that they don't get in a traffic jam
when you submit the form.
2) A better solution might be to generate the 8 forms in Python in
your actual view function. slap them in a list, and then just use the
template language to iterate them with a for loop. This way, you can
more easily manipulate the data before it gets to the template.
And when they submit the form back onto the same view, the view will
check for `request.method == "POST"`, and then verify that there are
no more than 8 being submitted. Defensive coding.
> Second thing I don't know is how to have the 8 subexperiments have their
> number automatically set. Is there a way to create the 8 subexperiments
> when an experiment is created?
This can go in a couple of directions... If all you care about is the
way the name is display, you can make your __unicode__ method do
something like the following, assuming your top-level model was
"Parent", and your sub-level model was "Child"
def __unicode__(self):
total_children = self.parent.child_set.count()
return u'Experiment %d' % (i+1,) for i in range(0,
total_children)
This is a bigger hit to the database, but it could be totally
negligible if this is a fairly small project.
The idea is that you just count how many children there are, and
dynamically render a name based on their order. Once you create a new
one, it'll automatically get a name in sequence with the others.
I hope that helps.
On Nov 24, 8:11 am, Andreas Kuntzagk <
andreas.kuntz...@mdc-berlin.de>