I have an app that uses the Admin functionality to manage database tables. It is, in fact, the entire UI for the app since it’s a kind of HR Management tool.
I have figured out how to add a date/time field to my Employee Web UI – but it isn’t so pretty…
Is there a way to get Django magic to wrap the things displayed in the screenshot after the “Go” button to a second line so it looks a bit cleaner?
This is all the code I have for the form at the moment:
sales_profile_name = django_forms.ModelChoiceField(queryset=models.SalesProfile.objects.all(), required=False)
date_and_time_for_scheduled_profile_change = django_forms.SplitDateTimeField()
And this is a screenshot of the UI I’m talking about. Note the “0 of 100 selected” and other items that come after the “Go” button… I’d like to put everything after the “Go” button on a second line.
You can override any of the admin templates.
Make yourself familiar with what parts of the page are rendered by which templates, and modify them as you see fit.
Thank you for that link. I’ll look into that.
On a related note - an I correctly understanding that the date time fields are all text inputs? Not “pickers” of some type?
For example, the code below gets me an empty text box. Is there any widget that allows my user to pick a date and a time without having to type it in? Am I somehow missing something when I “initialize” this in code?
date_time_for_scheduled_profile_change = django_forms.DateTimeField()
See datefield, and the pages that that section of the docs links to.
Then see formfield_overrides and the comment about the admin in auto_now_add.
For a DateTimeField, Django actually creates two widgets, one for the date and one for the time, and uses the the corresponding widgets for each. (See SplitDateTimeWidget)
If you’re going to build your application around the admin, you will want to become very familiar with how it works internally. Read through the source code and the templates to understand how it all fits together.
I appreciate the suggested reading.
I’m just not familiar with all the options in Django so your hint about the AdminDateWidget was very helpful and gave me enough to find some examples online. Who knew you could pass a widget in?
I did a little searching online for examples and found a few possibilities which I experimented with. This is getting me what I need. In the Admin.
I do wish there was comprehensive training available for Django - I’d pay for it myself… But reading the source code isn’t something I can afford to do while coding for and supporting this inherited Django app and 4 other large Java/Kotlin services… My boss would be breathing down my neck to get to the next Jira ticket.
If I’m missing some part of the docs that show usage examples, do let me know. Or if you’re aware of really comprehensive Django training… The links we’ve been looking at are somewhat abstract - especially for someone unfamiliar… and there was no indication (unless I missed something) that it was possible to pass in a widget…
Anyway - thanks! This looks like it is working, although I need to test a bit.
date_time_for_scheduled_profile_change = django_forms.SplitDateTimeField(widget=AdminSplitDateTime())