I have some many2many fields with a lot of options to choose from and I'd like to have two multichoices for each one, on the left the available options and on the right side the chosen ones. Here is an example that Django does with the Groups.
I have two questions:
How is this kind of "widged" called?
How can I implement it using Django 1.5.1 in an easy way in order to use it in the frontend and in the backend forms? Is there a native option or a 3rd party app?
Thanks!
This widget is called FilteredSelectMultiple. It can be used in Django admin through filter_horizontal or filter_vertical property of ModelAdmin class. If you want to implement such a widget yourself, perhaps its source code may be helpful.
Related
I have a table with a foreign key. My problem is that ther's a lot of registers, so I need do that:
But all I've found was for the Admin Panel. Any idea for a custom form without admin?
Raw id, isn't needed any more, since there's autocomplete in the admin. This is also the solution for a model in the frontend. However, you should not bake it yourself, but just use Django Autocomplete Light. An excerpt from the tutorial:
Autocompletes are based on 3 moving parts:
widget compatible with the model field, does the initial rendering,
javascript widget initialization code, to trigger the autocomplete,
and a view used by the widget script to get results from.
I have several models with one-to-one relation. For example
class Task(models.Model):
initial_comment = models.OneToOneField('Comment')
# A pack of other fields
class Comment(models.Model)
body = RichTextField()
# A pack of other fields
I want to create "create view" based on form, that gives user ability to create task and initial comment there.
I can't use CreateView because it is based on only one model
I can't use ModelForm because it is based on only one model
I can create several forms, but I can't join them into one formset (forms are different)
I feel "inlineformset_factory" (InlineFormSet) should be used here, but I am not sure it suits best. Is there any 3rd party Django app to do that?
Sure I can create form myself, but I do not want to copy/paste all fields, their types, localized labels, validations and so on. I just want to list their names (like fields attibute).
I can also have 2 forms and support them everywhere and track dependencies manually (save comments first), like in How can create a model form in django with a one-to-one relation with another model , but I hope there has to be better solution.
If you wonder why do I need one-to-one: Comments are used heavily in other places and have different relations with different models.
The inline_formset factory is correct. There are no standard generic views for this, but there is a third party package with generic views to do what you are wanting. Its in the standard Django way of doing things.
https://github.com/AndrewIngram/django-extra-views
You probably want to use the CreateWithInlinesView for that.
Well, I found solution.
CreateWithInlinesView works perfectly with OneToOneField (after all, 1-to-1 is just a foreign key with constraint), but my main model here is Comment, not Task. So I should set Comment as model field in this view and Task as inline. It looks silly. I will create custom form or review my model structure.
I'm new at Python and Django development. I'm trying to make a simple blog.
Right now what i am trying to do is create a admin function to show comments that not approved by admin yet. I like to show that comments and offer accept or reject choices to admin.
The problem is, i don't know the steps. I made some searches online but couldn't find what we are looking for. What are the steps to do this? What i need to learn to do this?
How do i add add custom list, buttons and functionality? I don't event know where to write code for my custom admin functionality.
Ps: I'm not looking for someone to write code for me. I'm just looking for guidelines.
I recommend using django-admin-plus (https://github.com/jsocol/django-adminplus) which does exactly what you want:
AdminPlus aims to be the smallest possible extension to the excellent Django admin component that lets you add admin views that are not tied to models.
All AdminPlus does is allow you to add simple custom views (well, they can be as complex as you like!) without mucking about with hijacking URLs, and providing links to them right in the admin index.
I created my own user table. I've been learning how to use the admin panel and I saw there's already a user table.
Should I use it or mine? (for example connection, member panel etc...)
If I should use it how to update it?
If I shouldn't what do I have to use it for?
Use the one django provides.
If you want extra fields on your user, create an extension to the user model.
It's really easy to do, you can just create your own model and make it inherit from the django.contrib.auth.User model, or you can also look here:
Extending the User model with custom fields in Django for more awesome answers of how people are doing this exact thing
The title might not be very clear. I'll try to explain be giving examples.
In my project, I have 6 different "content" apps. And we have several plugins we can put in pages (django-cms) having the possibility to have a link to any of thoses 6 apps.
But now, the only way I have for doing so, is to add a Foreign key for each apps, in each plugin.
Is there a better way ? Or is there a form field with the ability to link multiple different apps ?
I think what you need is generic relations in forms and admin - does this help?