#30386: Admin foreign key widgets don't quote keys.
-------------------------------------+-------------------------------------
     Reporter:  Joshua Goodwin       |                    Owner:
                                     |  Oluwayemisi Ismail
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.admin        |                  Version:  dev
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Yhemisi):

 As regards to this ticket, I worked on it following this steps

 class House(models.Model):
     name = models.CharField(max_length=255, primary_key=True)
     def __str__(self):
         return self.name

 class Room(models.Model):
     house = models.ForeignKey(House, on_delete=models.CASCADE)
     def __str__(self):
         return self.house.name


 using the quote function from django.contrib.admin.utils should fix this

  def test_foreign_key_raw_id_widget_renders_quoted_pk_in_change_url(self):
         house = House.objects.create(name='?a=b')
         rel = Room._meta.get_field('house').remote_field
         w = widgets.ForeignKeyRawIdWidget(rel, widget_admin_site)

         # apply quote function to primary key value
         pk_quoted = quote(str(house.pk))

         # render the widget
         rendered = w.render('test', house.pk, attrs={})

         # check that the primary key is properly quoted in the rendered
 HTML
         self.assertIn(f'href="/admin_widgets/house/{pk_quoted}/change/"',
 rendered)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30386#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701865f872c42-9f99fa67-69d9-4c25-a03f-60775b1d21b0-000000%40eu-central-1.amazonses.com.

Reply via email to