django-admin

Django Get ID of the object in save()

亡梦爱人 提交于 2021-02-10 07:07:09
问题 I have some fixed number let say it is num = 1000 Now I have field which need to be sum of the object.id and num. I need this in save() something like below. def save(self, *args, **kwargs): num = 1000 self.special = self.id + num super(MyModel, self).save(*args, **kwargs) But self.id is known after save and field named special is required. How to get self.id? 回答1: First of all? Is the number you're trying to add a fixed number? If so, why do you have to store it in the db at all? You may

Remove or edit object name in admin.TabularInline

狂风中的少年 提交于 2021-02-10 06:47:20
问题 My tabular inline in the admin looks like this : How do I get rid of the DateDeCotisation_adherents object phrase ? For bonus points, why are there three empty lines at the bottom ? admin.py class DatesDeCotisationInline(admin.TabularInline): model = DateDeCotisation.adherents.through readonly_fields = ['datedecotisation'] can_delete = False models.py class DateDeCotisation(models.Model): date = models.DateTimeField() adherents = models.ManyToManyField(Adherent, related_name='adherents_du

Django admin view uploaded photo

倾然丶 夕夏残阳落幕 提交于 2021-02-09 05:36:45
问题 I have implemented photo upload in Django but I have a problem to view it Django admin. models.py class WorkPlacePhoto(models.Model): file = models.FileField(storage=FileSystemStorage(location=settings.MEDIA_ROOT), upload_to='uploads') Photos are saved in PATH_TO_APP/media/uploads/ and I can view them in my app. However, in admin panel, when I clicked on the link which admin app is generated it gives me 404 error as Request Method: GET Request URL: http://127.0.0.1/admin/wpphotos

Django admin view uploaded photo

偶尔善良 提交于 2021-02-09 05:36:44
问题 I have implemented photo upload in Django but I have a problem to view it Django admin. models.py class WorkPlacePhoto(models.Model): file = models.FileField(storage=FileSystemStorage(location=settings.MEDIA_ROOT), upload_to='uploads') Photos are saved in PATH_TO_APP/media/uploads/ and I can view them in my app. However, in admin panel, when I clicked on the link which admin app is generated it gives me 404 error as Request Method: GET Request URL: http://127.0.0.1/admin/wpphotos

Django Admin - Allow models to be shown for is_staff users

删除回忆录丶 提交于 2021-02-08 21:41:08
问题 I need to make some Django models available for is_staff=True users in the Django admin interface. I do not want to go for each user and assign them permissions or group permissions to the staff users. Which method do I need to override in ModelAdmin or BaseModelAdmin class or is there any other simpler way? I am using Django 1.4 Version 回答1: class TeacherAdmin(admin.ModelAdmin): def has_add_permission(self, request): return True def has_change_permission(self, request, obj=None): return True

Django Admin: add inlines dynamically

ぐ巨炮叔叔 提交于 2021-02-08 05:08:32
问题 class MyTemplateAdmin(admin.ModelAdmin): list_display = ('name') search_fields = ['name'] inlines = [ Template1Inline, Template2Inline, Template3Inline, ] This works fine. But what I need is to make it dynamic. Whenever the admin adds a new Template to the MyTemplate Model, that needs to be added to the inlines. Is there a way to do this? Please comment if I am not clear enough on my question. Thanks in advance! 回答1: I haven't tested this, but in theory you could do: class MyTemplateAdmin

How to make an admin action in django to download user's pdf files

无人久伴 提交于 2021-02-08 04:38:43
问题 I want to create an admin action to download users pdf files The user file would be uploaded in the media directory What and the admin should be able to download any file I tried using pdfkit to let him download the files but I couldn't > import pdfkit > > def downloadCV(self, request, queryset): > projectUrl = str(queryset[0].cv)+'' > pdf = pdfkit.from_url(projectUrl, False) > response = HttpResponse(pdf,content_type='application/pdf') > response['Content-Disposition'] = 'attachment;

Django admin site: how to create a single page for global settings?

﹥>﹥吖頭↗ 提交于 2021-02-07 13:52:21
问题 I would like to create a single page in the admin site of django where I can change some global variables of the website (title of the website, items in the navigation menu, etc). At the moment I have them coded as context processors but I would like to make them editable. Something similar to what happens in WordPress. Is this possible? I can store the data in the databse, but can I have a link in the admin site that goes straight to the first document record and doesnt allow the creation of

Django admin site: how to create a single page for global settings?

Deadly 提交于 2021-02-07 13:51:41
问题 I would like to create a single page in the admin site of django where I can change some global variables of the website (title of the website, items in the navigation menu, etc). At the moment I have them coded as context processors but I would like to make them editable. Something similar to what happens in WordPress. Is this possible? I can store the data in the databse, but can I have a link in the admin site that goes straight to the first document record and doesnt allow the creation of

Add context to every Django Admin page

℡╲_俬逩灬. 提交于 2021-02-07 12:18:40
问题 How do I add extra context to all admin webpages? I use default Django Admin for my admin part of a site. Here is an url entry for admin: urlpatterns = [ url(r'^admin/', admin.site.urls), ] And my apps register their standard view models using: admin.site.register(Tag, TagAdmin) My problem, is that I want to display an extra field in admin template header bar and I have no idea how to add this extra context. My first bet was adding it in url patterns like below: urlpatterns = [ url(r'^admin/'