django

using profiles in iPython and Django

I've got a Django product I'm using iPython to interact with. I'm trying to have modules automatically loaded when I start a shell: python manage.py shell I've copied .ipython/ipythonrc to the root directory of the project and added to the file: import_some module_name model1 model2 However, when I start the shell, these names are...

How to set a value of a variable inside a template code?

Say I have a template <html> <div>Hello {{name}}!</div> </html> While testing it, it would be useful to define the value of the variable without touching the python code that invokes this template. So I'm looking for something like this {% set name="World" %} <html> <div>Hello {{name}}!</div> </html> Does something like this e...

Reload django wsgi scripts without root

I have an install of django on apache using embedded wsgi. I DON'T have root on the machine. How can I tell apache to reload the python instance when I deploy new source code? I tried removing all the .pyc files and it still is running the old code. ...

define a django model relationship

Hi, I'm writing an app that have recursive relations like this (pseudocode): class atist: name = charfield (...) class press: pub = foreingkey(artist) class works: work = foreingkey(artist) class img: im = foreingkey(works) I'm was thinking if this is the better approach to solve this problem, or if ...

How can I pass data to any template from any view in Django?

Like a good little coder, all of my Django templates inherit from a base.html. Now I would like to add some functionality to the base to always show some interesting things. Some user statistics, or random posts, or feeds, etc. All of my views look like this: def viewname(request) : template_vales = {} // Stuff return rend...

Recursive URL Patterns CMS Style

Whenever I learn a new language/framework, I always make a content management system... I'm learning Python & Django and I'm stuck with making a URL pattern that will pick the right page. For example, for a single-level URL pattern, I have: url(r'^(?P<segment>[-\w]+)/$', views.page_by_slug, name='pg_slug'), Which works great for url...

Saving profile with registration in Django-Registration.

In Django-Registration it says you can save a custom profile when you save a user. But I have no idea what the documentation is asking me to do. Here is what they say: "To enable creation of a custom user profile along with the User (e.g., the model specified in the AUTH_PROFILE_MODULE setting), define a function which knows how to cre...

Resetting databases with having OneToOneField crossing different applications in Django

I'm getting the following error when I run ./manage.py reset app1: Error: Error: app1 couldn't be reset. Possible reasons: * The database isn't running or isn't configured correctly. * At least one of the database tables doesn't exist. * The SQL was invalid. Hint: Look at the output of 'django-admin.py sqlreset app2'. That's the S...

django character set with MySQL weirdness

I'm seeing OperationalError (1267, "Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '='") It looks like some of my variables are UTF8 strings 'name': 'p\xc7\x9d\xca\x87\xc9\x9f\xc4\xb1\xc9\xa5s Badge' Is this a configuration issue? If so, how can i solve it? I'd like to handle eve...

Serve a dynamically generated image with Django

How do I serve a dynamically generated image in Django? I have an html tag <html> ... <img src="images/dynamic_chart.png" /> ... </html> linked up to this request handler, which creates an in-memory image def chart(request): img = Image.new("RGB", (300,300), "#FFFFFF") data = [(i,randint(100,200)) for i in range(0,300,1...

Show the sql Django is running?

is there a way to show the sql that django is running while performing a query? ANSWER: import connection from django.db from django.db import connection print connection.queries [{'sql': 'SELECT polls_polls.id,polls_polls.question,polls_polls.pub_date FROM polls_polls'; 'time': '0.002'}] ...

Active/Popular Google Code Django projects

I am python/django developer. As a part of improving my knowledge and felt like I need to "contribute" to the field of open-source, I started looking for django projects in code.google.com. There were many. I am not very sure which ones are popular and which needs help. Can you help me out in this direction, so that I instead of using ma...

Dynamic filtering on FK in Django Admin

I have one Product Model that has a FK to price, as one product can contain many prices. But I also want to be able to pick which one of those many prices should be the actual price, therefore I have both price (in Product Model) and product (in Price Model) to accomplish this. Consider these following models: class Product(models.Model...

How do I find the memory address of a Python / Django model object?

An ordinary object, I can use o.__repr__() to see something like '<__main__.A object at 0x9d78fec>' But, say, a Django User just returns <User:bob> How can I see the actual address of one of these, or compare whether two such model-objects are actually the same object or not? ...

Allow changing of User fields (like email) with django-profiles

Django lets you create a model foreign-keyed to User and define it in settings as the official "profile" model holding additional data for user accounts. django-profiles lets you easily display/create/edit that profile data. But the user's primary email address is part of their main account, not part of their extended profile. Therefore ...

Django template can't see CSS files

I'm building a django app and I can't get the templates to see the CSS files... My settings.py file looks like: MEDIA_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'media') MEDIA_URL = '/media/' I've got the CSS files in /mysite/media/css/ and the template code contains: <link rel="stylesheet" type="text/css" href=...

User upload profile pictures on django/jquery website in .jpg/.gif/.png format. How can I scale/crop them down when displaying them?

I'm letting users upload a profile picture for themselves on my site. These images are coming in on all different formats and sizes. When I display these profile photos I want them to be of a uniform pixel size without distortion. Do I have to have the user crop the image right when they upload it? Given a randomn image, how can I sc...

How to preset the username in Djangos login form?

After being dissatisfied with the existing solutions I wrote an OpenId provider for Django. If now somebody wants to authenticate himself somewhere as http://tejp.de/users/abc/ and needs to login for that, I want to display the login form with the username preset to "abc". The standard functions like redirect_to_login don't seem to prov...

Not null ForeignKey('self')

How can I make a ForeignKey refer back to the object itself? I'm trying : Alias(MyBaseModel): type = models.ForeignKey('self') a = Alias() a.type = a a.save() But then when I run it : (1048, "Column 'type_id' cannot be null") I don't want the type to be null, I want it to contain its own ID. I have tons of objects, but only 1 ...

How do I store multiple values in a single attribute

I don't know if I'm thinking of this the right way, and perhaps somebody will set me straight. Let's say I have a models.py that contains this: class Order(models.Model): customer = models.foreignKey(Customer) total = models.charField(max_length=10) has_shipped = models.booleanField() class Product(models.Model): sku = models....