Skip to content

Instantly share code, notes, and snippets.

@helmetwearer
Last active September 18, 2023 19:05
Show Gist options
  • Save helmetwearer/0cc66662144d1ee67ef341716b39e45a to your computer and use it in GitHub Desktop.
Save helmetwearer/0cc66662144d1ee67ef341716b39e45a to your computer and use it in GitHub Desktop.
class NormalModelWereExtending(BaseModel):
id = models.CharField(primary_key=True, db_column='id')
name = models.CharField(db_column='mycolumn')
class Meta:
managed = False
db_table = 'MyTable'
class MyProxyManager(models.Manager):
def get_queryset(self , *args, **kwargs):
queryset = super().get_queryset(*args , **kwargs)
# here we look at division = 3 or whatever the specific is
queryset = queryset.filter(type = 3)
return queryset
class MyProxyModel(NormalModelWereExtending):
class Meta :
proxy = True
objects = MyProxyManager()
def save(self , *args , **kwargs):
# set our type in save every time since we're in the proxy
self.type = 3
return super().save(*args , **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment