django admin widget

35 views
Skip to first unread message

thebob...@gmail.com

unread,
Oct 12, 2018, 9:43:26 PM10/12/18
to Django users
Hi,
I'm still a bit new to django, but making slow progress.

I'm wondering how to move forward with a book class as model which has an author field which
allows adding additional authors.

I have three fields allocated in the SQLite db for up to three different authors.

What I'm trying to do is only expose the additional author text entry box for the book class in admin
when say for example a plus or other widget is clicked.

ex.  Author [          ]  +
...then
      Additional Author1 [         ]  +
...and finally
      Additional Author2 [         ]

So if you click the plus the additional author1 text entry shows up, then click again the last or third
author entry shows up, but no more plus we're out of db fields at that point.

Not trying to dynamically add fields to the db.  Just expose when needed for up to three authors.

Prefer to not use jquery and/or javascript, but stick to pure python django if possible.

I've been reading alot about admin but still confused as to best way to proceed.

Thank You,

Ryan Nowakowski

unread,
Oct 13, 2018, 6:10:01 PM10/13/18
to Django users
I've done something similar in the past but I use a separate model for author that has a foreign key back to book. You can limit the number of authors to 3 in the author save method.

Then you can use an inline form for author in the admin. That will give you the + functionality you're looking for.

If you want to keep you current book model the same with authors as fields, take a look at admin fieldsets.

Bob Bobsled

unread,
Oct 15, 2018, 8:06:36 PM10/15/18
to django...@googlegroups.com
Hi,
The idea for a separate model for author with a foreign key back to book is interesting.  I hadn't thought of that.  Thanks for the ideas about how to approach this problem.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/96rMeBTLgOY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/38283332-0AB7-4F6B-93E2-F4BD347CAFD6%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages