Questions tagged [django-admin]

1

votes
2

answer
441

Views

How To Edit ManyToManyField In Django Admin list Display Page?

I want to add Many2Many fields editable in Django admin list_display page. The model structure as below, class Genre(models.Model): name = models.CharField(max_length=250, unique=True) class Movie(models.Model): name = models.CharField(max_length=250) genre = models.ManyToManyField(Genre) And I tri...
1

votes
2

answer
652

Views

Using contentType for raw_id_fields

In my application, i have a model definition like: class SomeModel(models.Model): someFK = Models.ForeignKey(SomeModel, null=True, blank=True) otherFK = Models.ForeignKey(OtherModel, null=True, blank=True) ... This model keep data about Logs, and there are more than 1 kind of model to be logged, so...
FallenAngel
0

votes
0

answer
6

Views

Django: create an admin section gathering info from multiple models

I've been asked to add in the admin site of a Django project a new section that will gather information from several models (as it were a Database view) but I'm not allowed to change or add tables/views in the db. Checking similar questions custom page for Django admin in SO, I've ended up trying to...
Manu
1

votes
2

answer
349

Views

Filter records before Django admin renders a model data

So, I have a model named foo. My requirement is to show a filtered list of records on the admin dashboard for foo. Basically, I want to filter the QuerySet even before admin renders the view for foo. Is there a way to do this? My environment: Django == 1.7, Python == 2.7 I use Grappelli to render m...
Piyush Das
0

votes
0

answer
22

Views

Why when I run one test it passes, but when I run all the tests, it falls

I wrote tests for the administrator interface in django project and all tests pass separately, but when I run the class with tests, it fails. Class with tests (test_admin.py): from django.forms.models import model_to_dict from django.test import TestCase from core.tests.test_data import TestDataAbs...
Anton Belsky
1

votes
0

answer
179

Views

Django Admin, including reverse foreignkeyfields on page

I have the following two models: class Seller(models.Model): name = models.Charfields(max_lenght=500) (... more fields, but no foreignkeys to anyone) class Ad(models.Model): seller = models.Foreignkey(Seller, related_name='ads') (... more fields that are not relevant to this question ) Now I want to...
Jasper
1

votes
0

answer
36

Views

Django admin, ManyToManyField -> ForeignKey relation

Suppose I have these models (with some properties omitted obviously): class Product(Model): name = CharField(max_length=100) class Variety(Model): product = ForeignKey(Product) class ProductMerge(Model): parent_product = ForeignKey(Product) products = ManyToManyField(Product, related_name='merge_pro...
Francisco Couzo
1

votes
1

answer
919

Views

How to resolve FOREIGN KEY constraint failed

I am following a tutorial on a basic concept. How to customize a user in django. I don't want to use the built in auth user. I found this tutorial which seems to work until a point. I get through the whole tutorial with everything working. however when I run my project, log in and open the user in t...
Daniel Tate
1

votes
1

answer
40

Views

Customize Users inside Django Admin

I want to add some fields in Users section, apart from the predefined ones. I want to add a section called 'Objectives' and also another called 'Tests'. How can I do this?
Enrique Vargas
1

votes
0

answer
150

Views

Saving Many-To-Many Field with self-reference in django-admin

I am trying to save a many-to-many field with self reference through django-admin. This is my model: class QuestionSetCategory(models.Model): parent_categories = models.ManyToManyField('self', blank=True) When I save the relation with django-admin, it outputs the following error: '' needs to have a...
Dominik Spiertz
1

votes
0

answer
216

Views

Django pre_save signal and ModelAdmin custom error message

I have a model whose pre_save() signal is connected to a remove service (json, REST, etc.) in the following way: before saving locally, query the remote service, asking for remote insertion remote service does its things, the main being checking that a relevant entry does not already exist. On succe...
Hal
1

votes
0

answer
70

Views

Django-cms no reverse match using apphook from admin

i hope you can help me. I'm using django 1.11 and django-cms. I created an apphook to manage urls from a certain page. I already created the page (with all translations) and associated it with my application so everything works fine. My problem occurs when, from admin, i'm inside the change page rel...
Beniamino Nobile
1

votes
1

answer
137

Views

Add reverse ForeignKey relation to existing instances from django admin

If I create a new model which is a ForeignKey of another, can I update existing instances of 'another' to have the new ForeignKeys as I create them? i.e. without going through the individual edit page of each instance of 'another'? Suppose that I have a Car model, and I create a bunch of Car instanc...
Guz
1

votes
1

answer
138

Views

In Django admin how can i hide or remove the Pencil, “+” and “x”?

I can hide all the options in the model base, but is not necessary, on the relation i can't do that i think that exist a simple form (not with css) to remove or hide it Thanks
1

votes
1

answer
435

Views

Django admin: how to save_model() in TabularInline?

I use Django 1.11.10 and python 3.6; I want create Item model in admin panel and add multiple File models at the same page, so I use TabularInline. The problem is before saving File models I need to fill out some other fields, for example size of uploaded file. If I use admin.ModelAdmin for class, t...
sirjay
1

votes
2

answer
144

Views

Django admin: how iterate over form attributes in ModelAdmin

I use Django 1.11.10 and python 3.6; I need to iterate form values in admin. How to do that? class ServerForm(forms.ModelForm): class Meta: model = Server def clean(self): setattr(self, 'field1', 'value1') setattr(self, 'field2', 'value2') class ServerAdmin(admin.ModelAdmin): form = ServerForm def s...
sirjay
1

votes
0

answer
153

Views

Add an extra total row in admin - Django

admin.py for an app is: from django.contrib import admin from django.db.models import Subquery, Sum, OuterRef from .models import GoodsItem, FinishedGoodsItem, SoldGoodsItem @admin.register(SoldGoodsItem) class SoldGoodsItemAdmin(admin.ModelAdmin): fields = ('date', 'goods_item', 'weight') list_disp...
rmalviya
1

votes
0

answer
39

Views

can django admin leverage rest framework filters?

I have setup my models to use: import rest_framework_filters as filters class FoundationIPFilter(filters.FilterSet): foundation_ip_team_group = filters.RelatedFilter(FoundationIPTeamGroupFilter, name='foundation_ip_team_group', queryset=FoundationIPTeamGroup.objects.all(), lookups='__all__') techno...
Emmanuel Sifakis
1

votes
0

answer
345

Views

Can't login to admin site. Returns a page not found error

I am trying to host my website at a2hosting shared hosting plan. I was told to use cpanel to create a virtualenv and then, use passenger to run django. My virtualenv folder and project folder are in the root directory. After setting everything and running collectstatic and creating a superuser, I tr...
Tanvir Ahmed
1

votes
1

answer
221

Views

How can I implement the Django Admin Foreign Key's Add button?

I would like to implement the add button we have beside a ForeignKey field, so that we can add data to the field/database. I have been following a couple tutorials, but none of them help me actually add data to the field, and in turn, my database. I have also been looking everywhere but I can't seem...
juiceb0xk
1

votes
0

answer
21

Views

how to handle new button in submit_line.html in django

i already create a class to validating xml file, and i try in actions its work but how i can make the script work in new button i create in submit_line.html this is my admin.py with actions class CrsFileAdmin(admin.ModelAdmin): list_display = ('fi', 'file', 'import_datetime', 'state') readonly_field...
putra
1

votes
1

answer
43

Views

Django Administration: Combine admin application model

I am using all auth and created another model ambassadors. I have currently the issue that Django Administration shows me these both models now in two different boxes. Does anyone know how to combine these? Preview My goal is to have Accounts: Email-Addresses Ambassdadors
1

votes
1

answer
151

Views

Django admin change_view not called

I'm trying to redefine a ModelAdmin for a model in this way: class MakeModelAdmin(admin.ModelAdmin): ... # def changeform_view(self, request, object_id, form_url='', extra_context=None): # if not request.user.is_superuser: # self.exclude = ('company',) # extra_context = extra_context...
RedPelle
1

votes
0

answer
813

Views

Django admin panel django.db.utils.IntegrityError: FOREIGN KEY constraint failed

I am using django version 2.0 getting integrity error while trying to add model element from admin panel. Although i can add element from shell. models.py class Book(models.Model): name = models.CharField(max_length=30) def __str__(self): return self.name admin.py admin.site.register(Book) i am usi...
somil
1

votes
0

answer
75

Views

pass parameter to change_form.html in user form of django admin site

I want to pass songname list and songcount list to user update page at admin side. I've already extended admin templates. Just want to know how can I pass custom parameters to user update page. My codes below change_form.html: {% extends 'admin/change_form.html' %} {% block after_related_objects...
Mek Vala
1

votes
0

answer
164

Views

How to pass context to DjangoAdmin's change_list_results.html

I currently have the following in my admin class def changelist_view(self, request, extra_context=None): context = extra_context or {} context['econtext'] = 'Extra Context' return super(BaseModelAdmin, self).changelist_view(request, extra_context=context) However, calling {{ econtext }} in my change...
Lorenzo Ang
1

votes
1

answer
165

Views

How do I reverse the URL for an admin action?

I'm posting this because I searched stackoverflow and docs for a long time without finding an answer -- hopefully this helps somebody out. The question is, for testing purposes, how do I find the URL that's related to admin actions for a specific model? Admin model urls can all be found by reverse(a...
Sam Bobel
1

votes
1

answer
129

Views

list_filter on auth.user in admin site

I am trying to add list_filter on User model in admin site. Following is the model: class Profile(User): user = models.OneToOneField(User) is_admin = models.BooleanField(default=False) I want to add list_filter on the Auth User for the user's get filtered based on 'is_admin' flag from Profile model....
108
1

votes
1

answer
44

Views

How to undisplay the field with empty value in django admin?

I am currently working on django. I created 4 classes in models.py, one of them is ReactionMeta class. This class has 62 columns, which defined as below: class Reactionsmeta(models.Model): id = models.ForeignKey('Reactions', db_column='id', primary_key=True, max_length=255, on_delete=models.CASCADE)...
HAOYANG MI
1

votes
0

answer
109

Views

How can I make django url alias?

I am using django rest framework filters in my app. For a viewset that looks like following: class ProductViewSet(viewsets.ModelViewSet): queryset = Product.objects.all() serializer_class = ProductSerializer lookup_field = 'slug' filter_backends = (SearchFilter, DjangoFilterBackend,) filter_fields =...
sadaf2605
1

votes
0

answer
39

Views

A confused about database structure and displacement on django admin

I am currently working on django and get confused about how to design the model. Right now, I have a table named 'Reactionmeta' which structure like below: 1 2 3 4 5 6 reaction name metabolite1 stoichiometry1 ....... metabolite60...
HAOYANG MI
1

votes
0

answer
34

Views

How to show link to all objects with same foreign key from Django Admin change page

I am trying to link directly from the change page of a Company Year in Django Admin to the other changepages of Company Year that have the same Company as a foreign key. Currently I have a link from the change page to the company page, and there I have links to all Company Years related to this comp...
Andreas
1

votes
1

answer
41

Views

Patient user can be Responsible from himself - Django Admin

First of all I would like to say that I am extremely new to Django and Python. I am writing an application using Django 2.0. I have two inheritances to the user: the patient and responsible. A patient needs a user to exist and a responsible needs a patient to exist. A responsible may have several...
ebmm01
1

votes
1

answer
86

Views

Use ugettext and ugettext_lazy in the same file in Django project

I'm working on translating a Django project. Nearly everything works fine. I just can't get django to collect strings marked with something else than _ (underscore). Let me explain a bit more : so as the doc stipulates, I'm using ugettext and ugettext_lazy. I think I've understood well enough why an...
MoaMoaK
1

votes
3

answer
973

Views

Upload multiple files using Files Field in Django Admin

Here i have class models: models.py class Parameter(models.Model): files = models.FileField( upload_to='uploaded', blank=True, null=True, ) and i have this in my admin.py class ParameterAdmin(admin.ModelAdmin): form = Parameter and i add it in my forms.py so it can select more then one file class Pa...
Faizalprbw
1

votes
0

answer
194

Views

Unique Together key validation error in Django admin inline forms

I have following structure of models A, B and C. class A(models.Model): id = models.IntegerField(primary_key=True, editable=False) name = models.CharField(_('Name'), max_length=40) ... ... class B(models.Model): id = models.IntegerField(primary_key=True, editable=False) a = models.OneToOneField(A, v...
Darshit
1

votes
0

answer
116

Views

One-to-many inline select with django admin 2018 UPDATED

I faced with the same issue as described here or here. In short: I have 2 models: Book and Shelf. In admin form ('add shelf') I would like to select from the books that are already in the library. By default this is not available. I used the solution (from links above) and everything works until I t...
Artur Bednarz
1

votes
0

answer
33

Views

Change models.AutoField(primary_key=True) to Hexadecimal

I am using django with mongodb using the djongo ORM. I am facing a problem. I want to set id to be the autofield and according to django AutoField is of IntegerField type. But when it is inserted in mongodb, mongodb uses its conventional 12byte hexadecimal value. This is the problem why I cannot edi...
Mr. Blue
1

votes
1

answer
35

Views

Django Admin additional custom field is hidden

I want to show the image src, as a field tag in Django Admin and I have: class AImageAdmin(AdminFilteringFK, AdminListImageModel, admin.ModelAdmin): model = AImage list_display = ('image_tag', 'a', 'filename', 'file_type') fields = ('a', 'image', 'image_tag', 'filename', 'file_type') readonly_fields...
user3541631
1

votes
0

answer
53

Views

django-admin How could i mark field readonly based on condition?

I have a model that I want to add 2 fields on it (1 field boolean and the other is float) I want to activate editing the float variable only if the boolean field is true otherwise the float field show be disabled or readonly I tried to override get_readonly_fields but I couldn't make it work due to...

View additional questions