Last active
September 18, 2023 19:05
-
-
Save helmetwearer/0cc66662144d1ee67ef341716b39e45a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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