-2

Following the style of the Django tutorial I want to add records in the TabularInline style on the main table, not in the master/detail style used in the tutorial.

The ideal approach would be to have a list_display and specify how many empty rows should be inserted or appended to the list when you click to add records.

Is there a way to accomplish this in Django? I am starting on 1.3

vfclists
  • 19,193
  • 21
  • 73
  • 92
  • which Django tutorial are you referring to? – Simon Kagwi Dec 06 '11 at 16:35
  • The introductory one - https://docs.djangoproject.com/en/1.3/intro/tutorial02/ – vfclists Dec 06 '11 at 17:14
  • Not possible. That's bad design, anyways. Putting repeating fields on a model (e.g., title1, title2, title3, etc.) kills kittens. – Chris Pratt Dec 06 '11 at 18:15
  • @ChrisPratt - What is wrong with it that? If it is okay to do it for master/detail why should it be wrong standalone? It can't be much different from adding records to a data grid or a spreadsheet. – vfclists Dec 06 '11 at 19:08
  • The main reason is one of extensibility. Inevitably, you'll eventually need to add more. With a M2M or Foreign Key, you're done for good, no matter what happens. Also, using relationships is more flexible. What if you want to loop through each set. You could hack something together with `getattr` and `setattr`, but with relationships, again, you're ready right out of the box. Repeating fields is a sign of poor planning and poor programming. You don't want to be that guy that the rest of curses later on. – Chris Pratt Dec 06 '11 at 19:12
  • I simply want to add records to a table the way I do in a spreadsheet. It is not linked to anything. What is wrong with that? It is not neither a master nor a detail in a master/detail setup. It is for my own use. Are they forbidden or not? Is it possible or not. – vfclists Dec 06 '11 at 19:31

1 Answers1

0

To do what you're asking, you would need to use your own view and a formset_factory to override the admin change list.

Brandon Taylor
  • 33,823
  • 15
  • 104
  • 144
  • I am new to django and may not be quite competent to judge the correctness of your answer, but after reading the docs it appears right. – vfclists Dec 07 '11 at 11:46
  • The admin is pretty easy to extend. Once you get to working with it and find the edges, you'll find all kinds of ways to modify it to suit your needs. Happy coding! – Brandon Taylor Dec 07 '11 at 14:05