To summarize before I get into bad examples, etc .: I am trying to create an application in which I do not need to write code in all my models in order to limit the selection to the current account (I'm not using Auth or built-in functions for account or login).
those. I do not want to do something like this:
class Ticket(models.Model):
account = models.ForeignKey(Account)
client = models.ForeignKey(Client)
content = models.CharField(max_length=255)
class TicketForm(forms.ModelForm):
class Meta:
model = Ticket
exclude = ('account',)
def __init__(self, *args, **kwargs):
super(OrderForm, self).__init__(*args, **kwargs)
if self.initial.get('account'):
self.fields['client'].queryset = Client.objects.filter(account=self.initial.get('account'))
- Account(models.Model) . , . - account ? ?
class TicketManager(models.Manager):
def get_query_set(self):
return super(TicketManager, self).get_query_set().filter(account=Account.objects.get(id=1))
, . .
: Django