Wrong ordering of many-to-many fields with explicit intermediary model in Django admin

2023-11-01 Thread Alan Evangelista
Hi, all.

I have a Submission model with a many-to-many relationship with a Market 
model and explicitly defined a SubmissionMarket model as intermediary 
model. I have defined
Submission inlines in a ModelAdmin class (used by Django admin) and defined 
the markets field as the first one in the fields attribute of a form 
associated with that submission inline. However, that field is being shown 
by last (at the end of the inline row). 

Debugging, I found out that:

- django.forms.models.fields_for_model() creates a dict of form fields for 
a Django model. That function is used during the construction of any form.
- a form field defined in the Form.Meta.fields is ignored in 
fields_for_model() if formfield_callback is passed as argument and if that 
callable returns None
- django.forms.models.ModelFormMetaclass 
passes BaseModelAdmin.formfield_for_dbfield as formfield_callback arg in 
fields_for_model() 
- This formfield_for_dbfield() method ends up 
calling formfield_for_manytomany() if the field is m2m. The latter method 
returns None if the intermediary model was not created automatically by 
Django, which causes the field to be ignored. This is the code that does it 
in django/contrib/admin/options.py:

# If it uses an intermediary model that isn't auto created, don't 
show
# a field in admin.
if not db_field.remote_field.through._meta.auto_created:
return None

- Later, the markets field is added at the end of the form, I haven't 
investigated why.

My question is: what's the motivation of ignoring the m2m field if the 
intermediary model is not auto created? Could this behavior be customized?

Thanks in advance!

Regards,
Alan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0974c9a3-3e03-42bb-a862-922ad68e329an%40googlegroups.com.


Re: NoReverseMatch at / Reverse for 'add_time_slot' with arguments '('',)' not found. 1 pattern(s) tried: ['add_time_slot/(?P[0-9]+)/\\Z']

2023-11-01 Thread Migui Galan
thank you! i think this is because you are not looping or have a turf_id in
the template. by 'loop' or have you tried '/add_time_lot//'?

On Wed, Nov 1, 2023 at 10:53 PM Sudharsan  wrote:

> urlpatterns = [
> path('', views.home, name ='home'),
> path('home/', views.allTurfs,name = 'allturfs'),
> path('profile/', views.dashboard, name = 'profile'),
> path('about/', views.about, name = 'about'),
> path('add_venue/', views.add_Turf, name = 'add_turf'),
> path('/', views.allTurfs, name='turf_by_place'),
> path('/', views.Turf_det, name='turf_det'),
> path('add_time_slot//', views.add_time_slot, name=
> 'add_time_slot'),
> ]
>
> On Wednesday, November 1, 2023 at 8:17:28 PM UTC+5:30 Migui Galan wrote:
>
>> Hi! can you include the urls.py code? this is mainly because you have not
>> included the  within the url setup
>>
>> On Wed, Nov 1, 2023 at 10:42 PM Sudharsan  wrote:
>>
>>> i getting an error while doing python django project. i was tried many
>>> things but nothing works. Please help me guys.
>>> [image: error.png]
>>> *views.py*
>>> # view for adding Turf page
>>> def add_Turf(request):
>>> submitted = False
>>> if request.method == "POST":
>>> form = TurfForm(request.POST)
>>> if form.is_valid():
>>> var = form.save(commit=False)
>>> var.created_by = request.user
>>> var.save()
>>> messages.info(request, ' Your Turf has added successfully')
>>> turf_id=var.id
>>> return redirect('add_time_slot',turf_id=turf_id)
>>> else:
>>> form = TurfForm
>>> if 'submitted' in request.GET:
>>> submitted = True
>>> return render(request, 'addvenue.html',{'form': form, 'submitted':
>>> submitted})
>>>
>>>
>>> # view for adding time slot
>>>
>>> def add_time_slot(request,turf_id):
>>> turf = Venue.objects.get(pk=turf_id)
>>> if request.method == 'POST':
>>> form = TimeSlotForm(request.POST)
>>> if form.is_valid():
>>> timeslot = form.save(commit=False)
>>> timeslot.turf = turf # Set the Turf for this TimeSlot
>>> timeslot.save()
>>> return redirect('add_time_slot', turf_id=turf)
>>> else:
>>> form = TimeSlotForm()
>>> return render(request, 'add_time_slot.html', {'form': form, 'turf':
>>> turf})
>>>
>>>
>>>
>>> [image: modelspy.png][image: modelspy2.png][image: error3.png]
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/439756cf-9e61-430f-8d28-c72afb9b4a49n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9a80543c-1b04-4e13-ba06-8b6ab029886en%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAKKJMPO4jA_J97cN28%2BWAWrhLRaddWPebBXdKkKPesphQapjpQ%40mail.gmail.com.


Re: NoReverseMatch at / Reverse for 'add_time_slot' with arguments '('',)' not found. 1 pattern(s) tried: ['add_time_slot/(?P[0-9]+)/\\Z']

2023-11-01 Thread Vincenzo Celano
I think the problem is in the data into turf_id. Are you sure that turf_id
contains only integer value? it's strange the problem with argument:
'('',)' - try to verify the data passed with turf_id if are correct...

Il giorno mer 1 nov 2023 alle ore 16:05 Adesewa Lola <
adesewalola2...@gmail.com> ha scritto:

> Hi Check your urls.py code
>
> On Wed, Nov 1, 2023 at 3:53 PM Sudharsan  wrote:
>
>> urlpatterns = [
>> path('', views.home, name ='home'),
>> path('home/', views.allTurfs,name = 'allturfs'),
>> path('profile/', views.dashboard, name = 'profile'),
>> path('about/', views.about, name = 'about'),
>> path('add_venue/', views.add_Turf, name = 'add_turf'),
>> path('/', views.allTurfs, name='turf_by_place'),
>> path('/', views.Turf_det, name='turf_det'),
>> path('add_time_slot//', views.add_time_slot, name=
>> 'add_time_slot'),
>> ]
>>
>> On Wednesday, November 1, 2023 at 8:17:28 PM UTC+5:30 Migui Galan wrote:
>>
>>> Hi! can you include the urls.py code? this is mainly because you have
>>> not included the  within the url setup
>>>
>>> On Wed, Nov 1, 2023 at 10:42 PM Sudharsan  wrote:
>>>
 i getting an error while doing python django project. i was tried many
 things but nothing works. Please help me guys.
 [image: error.png]
 *views.py*
 # view for adding Turf page
 def add_Turf(request):
 submitted = False
 if request.method == "POST":
 form = TurfForm(request.POST)
 if form.is_valid():
 var = form.save(commit=False)
 var.created_by = request.user
 var.save()
 messages.info(request, ' Your Turf has added successfully')
 turf_id=var.id
 return redirect('add_time_slot',turf_id=turf_id)
 else:
 form = TurfForm
 if 'submitted' in request.GET:
 submitted = True
 return render(request, 'addvenue.html',{'form': form, 'submitted':
 submitted})


 # view for adding time slot

 def add_time_slot(request,turf_id):
 turf = Venue.objects.get(pk=turf_id)
 if request.method == 'POST':
 form = TimeSlotForm(request.POST)
 if form.is_valid():
 timeslot = form.save(commit=False)
 timeslot.turf = turf # Set the Turf for this TimeSlot
 timeslot.save()
 return redirect('add_time_slot', turf_id=turf)
 else:
 form = TimeSlotForm()
 return render(request, 'add_time_slot.html', {'form': form, 'turf':
 turf})



 [image: modelspy.png][image: modelspy2.png][image: error3.png]










 --
 You received this message because you are subscribed to the Google
 Groups "Django users" group.
 To unsubscribe from this group and stop receiving emails from it, send
 an email to django-users...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/439756cf-9e61-430f-8d28-c72afb9b4a49n%40googlegroups.com
 
 .

>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/9a80543c-1b04-4e13-ba06-8b6ab029886en%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BPuKxrzMu7NrbopZ0orreBh7mb8H9O_4H8RfBNCQBvyC%2Bd%3DpA%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAB5pmX_ChdB8iTU8TYNS5Riw0kAKO-k%3DidAU5SvLrUqBarSjcg%40mail.gmail.com.


Re: NoReverseMatch at / Reverse for 'add_time_slot' with arguments '('',)' not found. 1 pattern(s) tried: ['add_time_slot/(?P[0-9]+)/\\Z']

2023-11-01 Thread Adesewa Lola
Hi Check your urls.py code

On Wed, Nov 1, 2023 at 3:53 PM Sudharsan  wrote:

> urlpatterns = [
> path('', views.home, name ='home'),
> path('home/', views.allTurfs,name = 'allturfs'),
> path('profile/', views.dashboard, name = 'profile'),
> path('about/', views.about, name = 'about'),
> path('add_venue/', views.add_Turf, name = 'add_turf'),
> path('/', views.allTurfs, name='turf_by_place'),
> path('/', views.Turf_det, name='turf_det'),
> path('add_time_slot//', views.add_time_slot, name=
> 'add_time_slot'),
> ]
>
> On Wednesday, November 1, 2023 at 8:17:28 PM UTC+5:30 Migui Galan wrote:
>
>> Hi! can you include the urls.py code? this is mainly because you have not
>> included the  within the url setup
>>
>> On Wed, Nov 1, 2023 at 10:42 PM Sudharsan  wrote:
>>
>>> i getting an error while doing python django project. i was tried many
>>> things but nothing works. Please help me guys.
>>> [image: error.png]
>>> *views.py*
>>> # view for adding Turf page
>>> def add_Turf(request):
>>> submitted = False
>>> if request.method == "POST":
>>> form = TurfForm(request.POST)
>>> if form.is_valid():
>>> var = form.save(commit=False)
>>> var.created_by = request.user
>>> var.save()
>>> messages.info(request, ' Your Turf has added successfully')
>>> turf_id=var.id
>>> return redirect('add_time_slot',turf_id=turf_id)
>>> else:
>>> form = TurfForm
>>> if 'submitted' in request.GET:
>>> submitted = True
>>> return render(request, 'addvenue.html',{'form': form, 'submitted':
>>> submitted})
>>>
>>>
>>> # view for adding time slot
>>>
>>> def add_time_slot(request,turf_id):
>>> turf = Venue.objects.get(pk=turf_id)
>>> if request.method == 'POST':
>>> form = TimeSlotForm(request.POST)
>>> if form.is_valid():
>>> timeslot = form.save(commit=False)
>>> timeslot.turf = turf # Set the Turf for this TimeSlot
>>> timeslot.save()
>>> return redirect('add_time_slot', turf_id=turf)
>>> else:
>>> form = TimeSlotForm()
>>> return render(request, 'add_time_slot.html', {'form': form, 'turf':
>>> turf})
>>>
>>>
>>>
>>> [image: modelspy.png][image: modelspy2.png][image: error3.png]
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/439756cf-9e61-430f-8d28-c72afb9b4a49n%40googlegroups.com
>>> 
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/9a80543c-1b04-4e13-ba06-8b6ab029886en%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2BPuKxrzMu7NrbopZ0orreBh7mb8H9O_4H8RfBNCQBvyC%2Bd%3DpA%40mail.gmail.com.


Re: NoReverseMatch at / Reverse for 'add_time_slot' with arguments '('',)' not found. 1 pattern(s) tried: ['add_time_slot/(?P[0-9]+)/\\Z']

2023-11-01 Thread Sudharsan
urlpatterns = [
path('', views.home, name ='home'),
path('home/', views.allTurfs,name = 'allturfs'),
path('profile/', views.dashboard, name = 'profile'),
path('about/', views.about, name = 'about'),
path('add_venue/', views.add_Turf, name = 'add_turf'),
path('/', views.allTurfs, name='turf_by_place'),
path('/', views.Turf_det, name='turf_det'),
path('add_time_slot//', views.add_time_slot, name=
'add_time_slot'),
]

On Wednesday, November 1, 2023 at 8:17:28 PM UTC+5:30 Migui Galan wrote:

> Hi! can you include the urls.py code? this is mainly because you have not 
> included the  within the url setup
>
> On Wed, Nov 1, 2023 at 10:42 PM Sudharsan  wrote:
>
>> i getting an error while doing python django project. i was tried many 
>> things but nothing works. Please help me guys.
>> [image: error.png]
>> *views.py*
>> # view for adding Turf page
>> def add_Turf(request):
>> submitted = False
>> if request.method == "POST":
>> form = TurfForm(request.POST)
>> if form.is_valid():
>> var = form.save(commit=False)
>> var.created_by = request.user
>> var.save()
>> messages.info(request, ' Your Turf has added successfully')
>> turf_id=var.id
>> return redirect('add_time_slot',turf_id=turf_id)
>> else:
>> form = TurfForm
>> if 'submitted' in request.GET:
>> submitted = True
>> return render(request, 'addvenue.html',{'form': form, 'submitted': 
>> submitted})
>>
>>
>> # view for adding time slot
>>
>> def add_time_slot(request,turf_id):
>> turf = Venue.objects.get(pk=turf_id)
>> if request.method == 'POST':
>> form = TimeSlotForm(request.POST)
>> if form.is_valid():
>> timeslot = form.save(commit=False)
>> timeslot.turf = turf # Set the Turf for this TimeSlot
>> timeslot.save()
>> return redirect('add_time_slot', turf_id=turf)
>> else:
>> form = TimeSlotForm()
>> return render(request, 'add_time_slot.html', {'form': form, 'turf': 
>> turf})
>>
>>
>>
>> [image: modelspy.png][image: modelspy2.png][image: error3.png]
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/439756cf-9e61-430f-8d28-c72afb9b4a49n%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9a80543c-1b04-4e13-ba06-8b6ab029886en%40googlegroups.com.


Django security releases issued: 4.2.7, 4.1.13, and 3.2.23

2023-11-01 Thread Mariusz Felisiak

Details are available on the Django project weblog:

https://www.djangoproject.com/weblog/2023/nov/01/security-releases/

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/328c78c5-f91a-4240-b018-cc55c230a53d%40gmail.com.