I have an application that uses multiple databases. Once the model instance object is in memory, how can I determine which database it came from? In particular, I would like to know this for use in a model class method.
Example:
class book(Models.model): newdate = models.DateField(default=date.today()) type = models.CharField( max_length=30, choices=BOOK_TYPE, default = 'novel', ) def get_current_student(self): if not hasattr(self,'_current_student'): try: self._current_student = clickerlog.objects.using(SELF.ORIGIN_DATABASE).get(book=self.pk,end__isnull = True).student except: self._current_student = none return self._current_student class booklog(Models.model): start = models.DateTimeField( default=datetime.now(), verbose_name = 'start time' ) end = models.DateTimeField(null=True,blank=True,) book = models.ForeignKey(book) student = models.ForeignKey(student, limit_choices_to = {'isactive':True})
Agdude
source share