Re: Tutorial

2012-04-20 Thread k4ml
On Apr 21, 8:59 am, Gerald Klein  wrote:
> I guess the problem I am having at this point is that the css files for
> admin are generated dynamically and I don't know where from as far as what
> the path should be that I could map it. I tried setting up the static
> mapping but I don't know what to point to as it's root.

No, it's not dynamically generated. Most django app will have static
files in their /static or for older app that does not yet
follow > 1.3 convention, they'll place their static files in /
media. You then need to collect all the static files for each app and
place it somewhere that your web server can serve it. If using apache,
you can put it under DocumentRoot of your vhost or set proper alias to
the directory where you collect all the static files in one place
(STATIC_ROOT). You don't have to do this manually since django > 1.3
provide app name staticfiles if enabled in your INSTALLED_APP provide
some helper command to collect all the static files into one place.
The doc explain this better.

If you want to do it manually, then just go through each of your
install app looking for directory name 'static'. For django admin as
an example:-

$ python
>> import django


Now I know to find the static for admin in /home/kamal/lib/python2.6/
site-packages/Django-1.3.1-py2.6.egg/django/contrib/admin/static.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: Overide error messages in models

2011-05-12 Thread k4ml
On May 13, 8:08 am, Daniel França  wrote:
> no way? I'll need to create new model forms?
>
> 2011/5/12 Daniel França 
> > I did that for some fields in my model, and the error message still is the
> > default message "This field is required".

I can't see any string 'error_messages' in django/db/models/' files so
the error message must be from django.forms. Maybe the documentation
is incorrect ? There's also no reference regarding error_messages for
models's field in the linked release page.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



newforms pre-populating with model

2008-02-24 Thread k4ml

I guess my use case is very common but somehow I can't find any
examples that did as what I want. I just want to provide a form to
edit an existing record so it supposed to be as simple as:-

Get the instance:-
customer = Customer.objects.get(id=1)

Create form instance and pass a dict of data from customer instance:-
form = CustomerForm(initial=customer.__dict__) #instance of ModelForm

The problem is, if my models has a foreign key fields, the rendered
select input would not set the initial value (selected) because the
select input name="state" while the key in customer.__dict__ is
state_id.

The models:
class Customer(models.Model):
   state = models.ForeignKey(State, db_column='state',
verbose_name='Negeri')

and the form:-

class CustomerForm(forms.ModelForm):
   class Meta:
   model = Customer

>>> customer.__dict__
{'created': None, 'created_new': None, 'notes': u'Test', 'refferer':
1, 'state_id': u'kelantan', 'id': 2}

While customer.state is an instance of State object and does not
appear in .__dict__ and even it appear newforms won't render. The
solutions that I can think of:-

1) Use state_id as a db_column - Don't really like it since 'state'
better expressed the data it contain.
2) Explicitly set every form field - Don't like it either since it
some kind of violate DRY. The fields already explicitly defined in the
models so we should assumed that as an authoritative definition. We
just feed it with a dict and let the validation routine handle the
rest.

I'd really hope someone can point me to the right direction, maybe I'm
missing something somewhere ? Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---