Monday, October 29, 2012

Re: Connecting to external databases from Views.py

Thanks Tom for this info I have adjusted the models .py as such..

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(ModelReadOnly.Meta):
        db_table = u'APP_LOG'




On Monday, 29 October 2012 11:41:26 UTC+2, Tom Evans wrote:
On Mon, Oct 29, 2012 at 8:44 AM, Gregg Branquinho <gr...@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

Email Disclaimer | Quote Disclaimer | All business is undertaken subject to our General Trading Conditions, a copy of which is available on request and on our website www.freightman.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/pkwinU7PGOQJ.
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