Monday, October 29, 2012

Re: Connecting to external databases from Views.py

On Mon, Oct 29, 2012 at 8:44 AM, Gregg Branquinho <gregg@freightman.com> wrote:
> from django.db import models
>
>
> class ModelManagerReadOnly(model.Manager):
> def update(self, *args, **kwargs):
> pass
>
>
> class ModelReadOnly(models.Model):
> objects = ModelManagerReadOnly() # The ReadOnly manager.
>
> def save(self, *args, **kwargs):
> pass
> #raise NotImplemented
>
> def delete(self, *args, **kwargs):
> pass
>
> class Meta:
> managed = False
> abstract = True
>
>
>
> class AppLog(ModelReadOnly):
> log_no = models.AutoField(db_column=u'LOG_NO') # Field name made
> lowercase.
> module_id = models.CharField(max_length=25, db_column=u'MODULE_ID') #
> Field name made lowercase.
> user_name = models.CharField(max_length=25, db_column=u'USER_NAME') #
> Field name made lowercase.
> full_name = models.CharField(max_length=80, db_column=u'FULL_NAME') #
> Field name made lowercase.
> description = models.CharField(max_length=3500,
> db_column=u'DESCRIPTION', blank=True) # Field name made lowercase.
> date_time_stamp = models.DateTimeField(db_column=u'DATE_TIME_STAMP') #
> Field name made lowercase.
> class Meta:
> db_table = u'APP_LOG'

If you derive a model from a base class, and want the base class's
Meta class to have an effect, you must derive the child class's Meta
class from the base class's Meta class:

https://docs.djangoproject.com/en/1.4/topics/db/models/#meta-inheritance

The net result is that with your current code, the 'managed' attribute
on the Meta class does not exist on the derived classes.

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment