How do I display add model in tabular format in the Django admin?

2024/9/17 3:57:43

I'm just starting out with Django writing my first app - a chore chart manager for my family. In the tutorial it shows you how to add related objects in a tabular form. I don't care about the related objects, I just want to add the regular object in a tabular form. This is what I have in my admin.py

from chores.models import Chore
from django.contrib import adminclass ChoreAdmin(admin.ModelAdmin):fieldsets = [ (None,              {'fields': ['description', 'frequency', 'person']})]   admin.site.register(Chore, ChoreAdmin)

and I want when I click "add chore" that rather than seeing:

Description: _____
Frequency: ______
Person: _____

I want it to show:

Description: __________ | Frequency: _______ | Person: _____

Is this trivial to do, or would it take a lot of custom effort? And if it is easy, how do I do it?

Thanks!

Answer

OP is probably all set, but for new users reading this, refer to: https://docs.djangoproject.com/en/dev/ref/contrib/admin/

Basically following part in above link:


The field_options dictionary can have the following keys:

fields: A tuple of field names to display in this fieldset. This key is required.

Example:

{
'fields': ('first_name', 'last_name', 'address', 'city', 'state'),
}

Just like with the fields option, to display multiple fields on the same line, wrap those fields in their own tuple. In this example, the first_name and last_name fields will display on the same line:

{
'fields': (('first_name', 'last_name'), 'address', 'city', 'state'),
}
https://en.xdnf.cn/q/72789.html

Related Q&A

Python Matplotlib - Impose shape dimensions with Imsave

I plot a great number of pictures with matplotlib in order to make video with it but when i try to make the video i saw the shape of the pictures is not the same in time...It induces some errors. Is th…

Move x-axis tick labels one position to left [duplicate]

This question already has answers here:Aligning rotated xticklabels with their respective xticks(6 answers)Closed last year.I am making a bar chart and I want to move the x-axis tick labels one positio…

PUT dictionary in dictionary in Python requests

I want to send a PUT request with the following data structure:{ body : { version: integer, file_id: string }}Here is the client code:def check_id():id = request.form[id]res = logic.is_id_valid(id)file…

Does python have header files like C/C++? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 9 years ago.Improve…

python: Greatest common divisor (gcd) for floats, preferably in numpy

I am looking for an efficient way to determine the greatest common divisor of two floats with python. The routine should have the following layoutgcd(a, b, rtol=1e-05, atol=1e-08) """ Re…

Difference between @property and property()

Is there a difference betweenclass Example(object):def __init__(self, prop):self._prop = propdef get_prop(self):return self._propdef set_prop(self, prop):self._prop = propprop = property(get_prop, set_…

airflow webserver command fails with {filesystemcache.py:224} ERROR - Operation not permitted

I am installing airflow on a Cent OS 7. I have configured airflow db init and checked the status of the nginx server as well its working fine. But when I run the airflow webserver command I am getting …

Django REST Framework - How to return 404 error instead of 403

My API allows access (any request) to certain objects only when a user is authenticated and certain other conditions are satisfied.class SomethingViewSet(viewsets.ModelViewSet):queryset = Something.obj…

503 Reponse when trying to use python request on local website

Im trying to scrape my own site from my local server. But when I use python requests on it, it gives me a response 503. Other ordinary sites on the web work. Any reason/solution for this?import reques…

Dereferencing lists inside list in Python

When I define a list in a "generic" way:>>>a=[[]]*3 >>>a [[],[],[]]and then try to append only to the second element of the outer list:>>>a[1].append([0,1]) >>…