SQLAlchemy Model Django like Save Method?

You can extend your models with some simple crud methods to achieve something similar to Django ORM / ActiveRecord: # SQLAlchemy db_session setup omitted … Model = declarative_base(name=”Model”) Model.query = db_session.query_property() class CRUD(): def save(self): if self.id == None: db_session.add(self) return db_session.commit() def destroy(self): db_session.delete(self) return db_session.commit() class User(Model, CRUD): __tablename__ = ‘users’ id = … Read more

Django REST Framework: using TokenAuthentication with browsable API

You can’t use the browsable api with TokenAuthentication. You have to add SessionAuthtication to your settings (http://www.django-rest-framework.org/api-guide/authentication/#sessionauthentication): REST_FRAMEWORK = { ‘DEFAULT_AUTHENTICATION_CLASSES’: ( ‘rest_framework.authentication.TokenAuthentication’, ‘rest_framework.authentication.SessionAuthentication’, ),

Non-database field in Django model

As long as you do not want the property to persist, I don’t see why you can’t create a property like you described. I actually do the same thing on certain models to determine which are editable. class Email(EntryObj): ts = models.DateTimeField(auto_now_add=True) body = models.TextField(blank=True) user = models.ForeignKey(User, blank=True, null=True) editable = False … class … Read more

Only showing year in django admin, a YearField instead of DateField?

I found this solution which solves the whole thing quite elegantly I think (not my code): import datetime YEAR_CHOICES = [] for r in range(1980, (datetime.datetime.now().year+1)): YEAR_CHOICES.append((r,r)) year = models.IntegerField(_(‘year’), choices=YEAR_CHOICES, default=datetime.datetime.now().year) Edit the range start to extend the list 🙂

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)