The Django admin site makes use of a really cool widget:
How can I make use of this widget in my own applications? I don't see anything like that listed here.
From the docs:
The Django Admin application defines a number of customized widgets for calendars, filtered selections, and so on. These widgets define media requirements, and the Django Admin uses the custom widgets in place of the Django defaults. The Admin templates will only include those media files that are required to render the widgets on any given page.
If you like the widgets that the Django Admin application uses, feel free to use them in your own application! They’re all stored in django.contrib.admin.widgets.
In this case, you want the FilteredSelectMultiple widget. To use it, apply the widget on a form field like so:
my_field = forms.ModelMultipleChoiceField(queryset=MyModel.objects.all(), widget=FilteredSelectMultiple("verbose name", is_stacked=False))
Make sure to include the forms media in the template as it needs to include a few JS files.
Related
I'm quite new to Django and Wagtail, and I'm having some difficulty with what I think is a very basic use.
How do I allow Wagtail to edit an existing view's template, while serving that template using Django's serving mechanism?
Assume I have an app (HomePage) created to serve the site's main index (/). I have the HomePage's views set up to render template and certain elements dynamically. Now I want that template to be editable via Wagtail's CMS interface. Something as simple as an image on the frontpage, or a headline.
The closest I've gotten so far has been to follow the Wagtail beginner's tutorial to override the base HomePage class in my app's models.py. That only made my pages available via the /pages/ URL.
Thank you for any help.
Since your site's home page is not a Page object in the Wagtail sense, I'd suggest looking at Wagtail's facilities for managing non-page content - snippets and ModelAdmin would be possible candidates, but I reckon the site settings module would be the best fit.
A Setting model gives you a set of fields which can be configured for display in the Wagtail admin using a 'panels' definition, just like you'd get for a page model - with the important property that only one settings record exists per site. You can retrieve this record within your homepage view or template as shown in the docs, and output it on your template as desired.
One way do that, is to let Wagtail serve your homepage. You will need to change your project's url configuration accordingly, to make wagtail's urls serve the root of your site.
Then, you can pack your dynamic content into a custom template_tag and include in your homepage html template.
I am making a view, to make some POST requests on my Django server. I need a way to select something and the proper widget that I need for the same is Django admin panel's raw_id_fields.
Widget:
Popup:
I was looking for a jquery plugin to do the same, but couldn't find anything. Is there a plugin / widget to have this functionality in my own views.
Is there a way to use this exact widget in my views.
I found django-yaac whose README says that I can use this outside the admin. However I can't seem to figure out how to use this outside the admin.
I'm not sure if this helps you, but anywhere in your template you can access a model's id like this:
{{ myModelObject.id }}
You can use it in a hidden field or javascript variable, and then you can manipulate it however you like.
My admin page for a specific model has two stackedInlines. Currently they display one under the other. I would like them to display side by side so The page would look like this (don't have enough reputation to embed the image :[ )
Any easy way to go about this without having to write my own admin page?
If that's the only solution, how exactly would I go about that?
you can override Django admin template for each app in your project.
you just have too create same folder as your app in template directory and overriding html.
How to override and extend basic Django admin templates?
You can add CSS/Javascript to admin page by defining class Media.
You'll have to override the admin template to accomplish this. See roshan's answer for more info.
How to add app item to main django admin site menu without creating any database tables. So then i can just overwrite admin template for this app?
You can add admin/foo/ urls to your own views in your URLConf. See "Creating Custom Admin Views" here: http://www.djangobook.com/en/1.0/chapter17/
Now you just need to add links to it. Override your favorite admin template, and add the link over there.
First, you can create an custom admin view that is independent of the models in your application and override the admin/index.html to include the new link explicitly. Alternatively, you can also override the get_urls in the AdminSite class
There are saner and better ways to add a new custom admin view. If you still want to use a model however, you can simply extend a django model and mark it as a proxy and override it's template.
I'm new in Django, so I have a question about the admin site. I want to modify the user view. I want add some buttons(e.g. "activate") or links in the User-table. But I cannot find any script, where I could modify it.
Are you interested augmenting the behavior of the Django Users model as well? If it's just modifying the presentation in the admin area, have a look at the Django docs. The admin UI is customized by adding an admin.py file to your application and referencing the ModelAdmin class. From the docs:
For each of those models, optionally create a ModelAdmin class that encapsulates the customized admin functionality and options for that particular model.
Buttons and links sound like it can be done in the template. You may want to override add_form.html which renders the User form but you need to have this hierarchy in your templates directory
templates/
admin/
auth/
user/
add_form.html
This form extends "admin/change_form.html". For your reference, check out the actual code online.