﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
35641	Pattern matching on model objects	Johan Dahlin		"It would be nice if I could use pattern matching on Django model fields, this is especially important in context where I don't know what the model is, for example in a global post_save() handler where I want to do some specific logic based on a subclass.


{{{#!python
class Person(Model):
    name = TextField(...)
    age = IntegerField(...)

class Company(Model):
    address = TextField(...)
}}}

I would then be able to do
{{{#!python
@receiver(pre_save)
def pre_save(sender, instance, ....):
   # model comes in via signals or some other way, we don't know which subclass it is
   match model:
      # equivalent to isinstance(model, Person) and model.age > 10:
       case Person(age) if age> 10:
            ....
      # equivalent to isinstance(model, Company) and model.name.endswith('Street')
       case Company(address) if name.endswith('Street'):
            ....
       # or just extract and return a value
       case Person(name):
           return name
}}}

Happy to create a PR if this is interesting.
"	New feature	new	Database layer (models, ORM)	5.0	Normal			Johan Dahlin	Unreviewed	0	0	0	0	0	0
