Hi Marco, Thanks for writing a clear, short proposal.
This could be neat, but I'm against it for these reasons: - It's extra syntax - the advantage of the new URL syntax is that it's very simple and easy to pick up. It's copied from Flask, which also doesn't support a "multiple converter" syntax ( https://flask.palletsprojects.com/en/1.1.x/quickstart/#routing ). Instead, you're expected to define multiple routes if that's what you want. - It is only a shortcut - the behaviour you want can be achieve with multiple URL definitions. This is clearer in terms of readability and precedence (top to bottom). Understanding precedence could be a problem in particular for a multi-converter pattern like "<int|str:a>/<int|str:b>/" - does "int a, str b" have precedence over "str a, int b", or the other way round? - You can define a custom converter right now, as Richard suggests. Thanks for taking the time to write to the mailing list though, Adam On Fri, 30 Aug 2019 at 18:30, Richard <rea...@asymmetricventures.com> wrote: > A possibility without changes to Django is to create a generic converter > and apply it to each model: > > class ModelUUIDConverter: > regex= r'[a-fA-F0-9]{32}' > def __init__(self, model): > self.model = model > def to_python(self, value): > return self.model.objects.filter(Q(uuid=value)|Q(display_id=value). > get() > def to_url(self,value): > return str(value) > > urls.register_converter(lambda: ModelUUIDConverter(TicketModel), > 'ticket_or_uuid') > > path('api/<ticket_or_uuid:ticket>',TicketDetailView.as_view()) > > > > On Friday, 30 August 2019 11:12:08 UTC-6, Marco Silva wrote: >> >> Hello, >> >> I'm on the process of migrating an app to django >2 and walked into this >> potencial new feature while converting the URLs. >> >> Some modeles use a "display" id, like TICKET-2019-002, but it's pk is >> actually a uuid, so the url would ideally support both. >> >> I've created a custom converter to verify the correct value, therefore I >> can use: >> `path('api/ticket/<ticket:ticket>', TicketDetailView.as_view())` >> >> but if i want to also expose the api with the uuid, I have to add another >> urlpattern with: >> `path('api/ticket/<uuid:ticket>', TicketDetailView.as_view())` >> >> my proposal would be to add support for this: >> `path('api/ticket/<ticket|uuid:ticket>', TicketDetailView.as_view())` >> >> >> The concrete example is a different use case, its a "common" view where >> you must specify the type first, so basically: >> `path('api/<str:obj_type>/<ticket|task|epic|uuid:refecence_nr>/assign', >> GenericAssignView.as_view())` >> >> >> From what i've seen on the API, wouldn't be much work to add regex groups >> on the djanjo.urls.resolvers._route_to_regex method, but it also returns a >> converters dictionary with a mapping of parameters(the ticket, or >> refecence_nr) with a single converter, and that could cause problems >> somewhere... >> > -- > 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/d7cb9137-98bf-4db0-993b-538000321c65%40googlegroups.com > <https://groups.google.com/d/msgid/django-developers/d7cb9137-98bf-4db0-993b-538000321c65%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/CAMyDDM1s3z_m-45WGssGeU-xZQ_zfkfSHiciMUMhsMqHLfoi1Q%40mail.gmail.com.