Archive for August, 2014

Solving quotes issue in Templates while after using django-generate-scffolding

August 6, 2014 Leave a comment

‘url’ requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
Solution 1:

sed -i -r ‘s/url ([^”]+) %/url “\1” %/g’ template.html

solution 2: Run this one from templates folder.

find . -type f -print0 | xargs -0 sed -i ‘s/{% url \([^” >][^ >]*\)/{% url “\1″/g’

Categories: Django Tags: ,

Integrating Django with a legacy database

August 1, 2014 Leave a comment

After connect to your database.

Step 1:

python inspectdb

Outputs general models from your db that u defined it in settings file.

Step 2:

python inspectdb > ./your_app/

creates file from the output in *nix systems.

Step 3:

You’ll have to do the following manually to clean this up:

Rearrange models order

Make sure each model has one field with primary_key=True

Remove ‘managed = False’ lines if you wish to allow Django to create and delete the table

Step 4:

But it will have some problems like same table will more than one foreign key fields, those filed names should not have the related_name because with out related_name you django can’t figure out which field is connects to foreign key filed. To check this run the following command.

You will see the sqlcustom [appname] but dont run this command because it wont take the

python sqlcustom [appname]





%d bloggers like this: