InlineAdmin unable to delete object with read only primary key

2022-11-21 Thread Gagan Deep


Hello everyone! 

In my project, I have created a model (Token) which uses a custom primary 
key (i.e. it uses a field defined by the model for the primary key instead 
of using "id"). I created an InlineAdmin class for this model and added the 
primary key field to InlineAdmin.readonly_fields. This InlineAdmin is added 
to ModelAdmin.inlines of another model.

After making these changes, it is *not possible* to delete a Token object 
from the InlineAdmin (web interface). After selecting the delete checkbox 
for the Token object and clicking on the "Save and continue" button (of 
ModelAdmin), the page reloads with the Token object still there. 

I have created a simple Demo project to replicate this issue,  
https://github.com/pandafy/inline_admin_pk_bug.  

I have done some initial debugging, and found that when the primary key is 
added to the InlineAdmin.readonly_fields, an HTML input element for that 
field is not created. 

This does not occur when a model has "id" field for the primary key and the 
"id" field is added to InlineAdmin.readonly_fields. 

[image: Screenshot from 2022-11-21 23-05-22.png]

I believe this is inconsistent behaviour. I will be more than happy to open 
an issue for this on Trac and work on a potential fix if this is a bug. 

Regards, 
Gagan Deep 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/85d9b570-d3dc-46ca-8976-8ffcff061c01n%40googlegroups.com.


Re: InlineAdmin unable to delete object with read only primary key

2022-11-23 Thread Gagan Deep
Hi David! 

Thanks for double checking my work. Yes, I also see those errors in the 
admin. I was guessing that those were related to the primary key issue. 

- 
Gagan Deep 

On Tuesday, November 22, 2022 at 12:03:28 PM UTC+5:30 
shang.xia...@gmail.com wrote:

> Hi Gagan,
>
> Interesting quirk you've found there, it's possible it could be a bug 
> though further digging may be required.
>
> A couple of interesting notes I found while fiddling with your example 
> code:
>
>- If you press "Save and continue editing" there are unspecified form 
>errors
>- Setting `editable=False` on the token key fixes these unspecified 
>errors and also allows you to delete the token
>- Note that while inline works with `editable=False` it also means 
>that you can't create a disabled token because of the nature of how 
>checkboxes are handled. This is a separate issue.
>
>
> David
>
> On Tue, 22 Nov 2022 at 04:42, Gagan Deep  wrote:
>
>> Hello everyone! 
>>
>> In my project, I have created a model (Token) which uses a custom primary 
>> key (i.e. it uses a field defined by the model for the primary key instead 
>> of using "id"). I created an InlineAdmin class for this model and added the 
>> primary key field to InlineAdmin.readonly_fields. This InlineAdmin is added 
>> to ModelAdmin.inlines of another model.
>>
>> After making these changes, it is *not possible* to delete a Token 
>> object from the InlineAdmin (web interface). After selecting the delete 
>> checkbox for the Token object and clicking on the "Save and continue" 
>> button (of ModelAdmin), the page reloads with the Token object still there. 
>>
>> I have created a simple Demo project to replicate this issue,  
>> https://github.com/pandafy/inline_admin_pk_bug.  
>>
>> I have done some initial debugging, and found that when the primary key 
>> is added to the InlineAdmin.readonly_fields, an HTML input element for that 
>> field is not created. 
>>
>> This does not occur when a model has "id" field for the primary key and 
>> the "id" field is added to InlineAdmin.readonly_fields. 
>>
>> [image: Screenshot from 2022-11-21 23-05-22.png]
>>
>> I believe this is inconsistent behaviour. I will be more than happy to 
>> open an issue for this on Trac and work on a potential fix if this is a 
>> bug. 
>>
>> Regards, 
>> Gagan Deep 
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-develop...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/85d9b570-d3dc-46ca-8976-8ffcff061c01n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-developers/85d9b570-d3dc-46ca-8976-8ffcff061c01n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/49d2bd1e-7adc-49a9-bff6-a8f873ee686cn%40googlegroups.com.


Admin login view does not respect REDIRECT_LOGIN_URL

2023-10-16 Thread Gagan Deep
Hello everyone, 

While working on my project, I found that the admin login view does not 
respect the REDIRECT_LOGIN_URL 
<https://github.com/django/django/blob/f6629ee2c986d3bf59b4c1b3058f370a00bdc573/django/contrib/admin/sites.py#L427-L431>.
 
This could be design decision that I am overlooking (because admin is a 
special case?). 

In my limited time, I couldn't find a related discussion for this on 
Django's trac or GitHub repository (PRs). Hence, I wanted to confirm before 
opening a issue on trac. 

Regards, 
Gagan Deep 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/6ead2cb4-c88f-4b4e-bd6c-a531491454cdn%40googlegroups.com.


Configurable landing page in admin site

2020-12-23 Thread Gagan Deep
Greetings of the day,

I have use case where I want to show a custom landing page after a user 
logs into the admin site. One way to do it will be to override the 
index_template 
attribute of AdminSite 
<https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.AdminSite.index_template>,
 
but doing so will not let me use the index page generated by Django admin . 

I want to keep the index view intact while also providing a custom landing 
page logged in users on Django's admin site. I think such feature will be 
helpful for all users of Django. 

Best, 
Gagan Deep

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/c2774449-3a4d-45ad-99d1-0ef998154827n%40googlegroups.com.


Re: Configurable landing page in admin site

2020-12-24 Thread Gagan Deep
Thanks for sharing Adam. This should take care of my use case. 

Do you think there can be a potential use for introducing a 
setting/attribute dedicated for adding a landing page? 

Best, 
Gagan Deep

On Wednesday, December 23, 2020 at 8:37:22 PM UTC+5:30 Adam Johnson wrote:

> You can do this already by changing where the login redirects to in your 
> custom AdminSite class
>
> def login(self, *args, **kwargs):
> response = super().login(*args, **kwargs)
> if isinstance(response, HttpResponseRedirect):
> response = HttpResponseRedirect("/custom-page/")
> return response
>
> On Wed, 23 Dec 2020 at 14:59, Gagan Deep  wrote:
>
>> Greetings of the day,
>>
>> I have use case where I want to show a custom landing page after a user 
>> logs into the admin site. One way to do it will be to override the 
>> index_template 
>> attribute of AdminSite 
>> <https://docs.djangoproject.com/en/3.1/ref/contrib/admin/#django.contrib.admin.AdminSite.index_template>,
>>  
>> but doing so will not let me use the index page generated by Django admin . 
>>
>> I want to keep the index view intact while also providing a custom 
>> landing page logged in users on Django's admin site. I think such feature 
>> will be helpful for all users of Django. 
>>
>> Best, 
>> Gagan Deep
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django developers (Contributions to Django itself)" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-develop...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-developers/c2774449-3a4d-45ad-99d1-0ef998154827n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-developers/c2774449-3a4d-45ad-99d1-0ef998154827n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Adam
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/746c1d59-1921-4367-b398-f5f853478498n%40googlegroups.com.


Inheriting nav-global block in admin/base_site.html

2021-01-15 Thread Gagan Deep
Greetings of the day,

I was working with templates for the admin site of Django. I added some 
HTML elements to the *nav-global* block of the *admin/base.html* 
<https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/base.html>
 template, 
but surprisingly they did not show up on the final render page. Upon deeper 
inspection using *django-debug-toolbar*, I realized that the 
admin/base_site.html 
<https://github.com/django/django/blame/master/django/contrib/admin/templates/admin/base_site.html>
 template 
extends *admin/base.html* and overrides the *nav-global* block without 
adding anything to it.

In my opinion, *admin/base_site.html* should inherit the *nav-global* block 
of *admin/base.html* instead of overriding it. I wanted to discuss it 
before going ahead to open a ticket for this. I tried to find a reason for 
adopting the current implementation, but couldn't find anything even by *git 
blame.*

Best, 
Gagan Deep



-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/92c800a9-3b7b-4457-9e21-25976735cffcn%40googlegroups.com.


Implementation of view permission in Django admin

2022-01-04 Thread Gagan Deep


Hello everyone! 


I have been looking into the implementation of ModelAdmin and how it 
processes the view only permission. While rendering a ModelAdmin for a user 
with view-only permission, the ModelAdmin disregard widget defined for the 
field and uses the AdminReadonlyField 
<https://github.com/django/django/blob/155e06a50b7b65a7bb3c888ae51bdf1a2bd1a1e2/django/contrib/admin/helpers.py#L116-L121>
 to 
display the information. 


This implementation makes it difficult to customize the rendering of the 
object information. An example use case is rendering map for GeoJSON 
coordinates in django-lealet 
<https://github.com/makinacorpus/django-leaflet/issues/85>. 


I have already read discussions in 
https://code.djangoproject.com/ticket/17295 ticket and also checked related 
discussions on this mailing list. I couldn't find a discussion on how 
ModelAdmins that use custom forms (or widgets for fields) could be 
supported for view-only permission. 


Will adding support for customizing the rendering of ModelAdmin for users 
with view-only permissions be useful for Django? 


Best, 

Gagan Deep 

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/b85b8330-3180-46e4-9b46-1b3cd8124295n%40googlegroups.com.