Re: Optional foreign key with django?

2010-09-09 Thread maroxe
This solved my problem

On 9 sep, 12:18, Carlton Gibson <carlton.gib...@gmail.com> wrote:
> On 9 Sep 2010, at 12:04, bagheera wrote:
>
> >> On Sep 8, 11:14 pm, maroxe <bachir...@gmail.com> wrote:
> >>> Hi, In my models I want to have an optional field to a foreign key. I
> >>> tried this:
>
> >>>  field = models.ForeignKey(MyModel, null=True, blank=True,
> >>> default=None)
>
> >>> But i am getting this error:
>
> >>>  model.mymodel_id may not be NULL
>
> I think the error is that SQLite treats columns with defaults as NOT NULL.
>
> As far as I can see, you don't need the `default=None` in your model 
> declaration. Change it to:
>
> field = models.ForeignKey(MyModel, null=True, blank=True)
>
> -- I have multiple apps using SQLite that do exactly this, so to quote an 
> earlier post, "this should just work (TM)"
>
> HTH
>
> Regards,
> Carlton

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Returning an inclusion tagLLKKJJ

2010-09-09 Thread maroxe
Hi, I am suffering whereever i try to do something in django that is
not common(in django, not in python in general)

For example, i don't know how to return an inclusion tag. This.
obviously, won't work:

@register.inclusion_tag('template.tpl')
def myinclusiontag(parameter):
return {'var': parameter.attr1}


@register.inclusion_tag('template2.tpl')
def myinclusiontag2(parameter):
return {'var': parameter.attr2}

@register.simple_tag
def mysimpletag(paramter):
if parameter.attr: return myinclusiontag(parameter)
else: return myinclusiontag2(paramter)
mysimpletag return a dict(first returned by the inclusion tag), wich
is a normal behaviour, but this is not my i want.

help pls

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



How does django convert string to modules

2010-09-08 Thread maroxe
Hi, I am trying to understand an other magic thing about django: it
can convert strings to modules. In settings.py, INSTALLED_APPS is
declared like that:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
)
All it contains is strings. But django will convert those strings to
modules and import them later.

I want to do be able to do the same thing. but i don't know how. I
have a dictionnary of rederer dispatcher in settings.py:

RESOUCE_RENDERER = {
'video': 'video_player',
'audio': 'audio_player',
}
I want to use it later like this: RESOURCE_RENDERER'video' I cannot
assign directly the function name(eg video_player) because it lives in
a module that needs settings.py

Any idea?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django magic: context passed to template

2010-09-08 Thread maroxe
Hi, There is something i don't get in django template system. I have a
FileField in my model called myfile. If i pass an instance of my model
to a template, i can access file.size (this is an example). Form where
this variable 'size' come from?? it's not part of the FileField class
as far as i know. A small test:

def save(self):
  super(UploadItem, self).save()
  import logging; logging.debug(file.size)
this snippet generates this error: type object 'file' has no att

is django so magic?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Optional foreign key with django?

2010-09-08 Thread maroxe
Hi, In my models I want to have an optional field to a foreign key. I
tried this:

  field = models.ForeignKey(MyModel, null=True, blank=True,
default=None)

But i am getting this error:

  model.mymodel_id may not be NULL

i am using sqlite edit: if it can help, here is the exception
location:

  /usr/lib/python2.6/site-packages/django/db/backends/sqlite3/base.py
in execute, line 200

so it's sqlite specific problem, i think.

PS: i droped the whole table and synced before getting this error.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django not taking in consideration model fields declared in __init__

2010-09-07 Thread maroxe
Hi, When using Model class like this:

class MyModel(models.Model):
def __init__(self, *args, **kwargs):
self.myfield = models.Field()
super(MyModel, self).__init__(*args, **kwargs)
It doesn't take into consideration myfield(in the admin form, when
saving the object... )

But if i declare like that:

class MyModel(models.Model):
myfield = models.Field()
It works just fine.

Why?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Forms.is_valid() Always return False

2010-07-11 Thread maroxe
The problem occurs only when using AuthenticationForm!

On Jul 11, 4:14 pm, maroxe <bachir...@gmail.com> wrote:
> Hi all,
> I have a problem with django 1.2:
>  is_valid returns always False, and form.errors is empty.
> I use AuthentificationForm provided by django.
> I have created a bound form:
> form = AuthentificationForm(request.POST)
>
> and this request.POST:
>  [u'f871257kikf70a95e1197c8af01597eb'], u'password': [u'mypass']}>
>
> I believe it's a probleme related to django new securitiy system
> against csrf attaks.
>
> Any help pls?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Forms.is_valid() Always return False

2010-07-11 Thread maroxe
Hi all,
I have a problem with django 1.2:
 is_valid returns always False, and form.errors is empty.
I use AuthentificationForm provided by django.
I have created a bound form:
form = AuthentificationForm(request.POST)

and this request.POST:


I believe it's a probleme related to django new securitiy system
against csrf attaks.

Any help pls?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.