for field in OrderAddress._meta.fields:Reference: http://stackoverflow.com/questions/5358800/django-listing-model-field-names-and-values-in-template
field.name
user = User.objects.latest('pk')
for field in user._meta.fields:
field.name, field.value_to_string(user)
Sunday, 3 November 2013
Django - Get Model Field's Name
Monday, 21 October 2013
Django - Loop Form Cleaned Data
for key, value in form.cleaned_data.iteritems():Python 3
print key, value
for key, value in form.cleaned_data.items():Reference:
print (key, value)
http://stackoverflow.com/questions/5904969/python-how-to-print-a-dictionarys-key
Django - Foreign Table Relational Mapping Queryset
def get_child_attribute_list(self, element):
return Attribute.objects.filter(Q(element=element), Q(productattribute__product__parent=self)|Q(productattribute__product__root=self))
Monday, 14 October 2013
Django - Link Sub-instance to Inheritance Model
def save_to_finishing(self):
finishing_product = FinishingProduct(product_ptr_id=self.pk)
finishing_product.__dict__.update(self.__dict__)
finishing_product.save()
Reference:
http://stackoverflow.com/questions/4064808/django-model-inheritance-create-sub-instance-of-existing-instance-downcast
Thursday, 12 September 2013
Django - Site Matching Query Error
Site matching query does not exist. Lookup parameters were {'pk': 1}Open Project Shell
python manage.py shell
Create Site Object
from django.contrib.sites.models import SiteBest Practise
Site.objects.create(pk=1, domain='example.com', name='example')
python manage.py syncdb --noinput
python manage.py migrate
python mange.py createsuperuser
Sunday, 8 September 2013
Python - Fix Non-ASCII Character in File
Encode in ANSI
Additional Headers (On Top of code)
EXTRA: For Windows (Optional)
Additional Headers (On Top of code)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
EXTRA: For Windows (Optional)
Python - Windows UTF-8 Cmd Input
Create win32_unicode_argv.py
Import
http://code.activestate.com/recipes/572200/
http://stackoverflow.com/a/846931
Import
import sysReference:
import win32_unicode_argv
http://code.activestate.com/recipes/572200/
http://stackoverflow.com/a/846931
Subscribe to:
Posts
(
Atom
)