Re: How change field to "unique" in existing mysql database?

2011-05-14 Thread AJ
South is another Django app that you can run on demand when you make a
change to your app Models.

Why do you want to uninstall South after the alteration? Let it be there and
manage your App Models with South. It is better than just syncdb.




On Sun, May 15, 2011 at 12:49 AM, Chris Seberino wrote:

> Shawn
>
> Thanks!  Is South just a script that runs?  Can I uninstall after the
> conversion if desired?
>
> Or, does it permanently alter a Django app somehow?
>
> cs
>
> On May 14, 10:53 pm, Shawn Milochik  wrote:
> > The best way is to use South.
> >
> > http://south.aeracode.org/
> >
> > In your current situation, after you install South (pip install then add
> > to INSTALLED_APPS, and syncdb to add the South table) you'll just have
> > to do this:
> >
> >  1. manage.py convert_to_south appname #this will set up the basics,
> > you'll only do this once
> >
> >  2. change your model #it should not have changed since the initial
> > syncdb until this point
> >
> >  3. manage.py schemamigration appname name_your_migration --auto
> > #create a South migration file
> >
> >  4. manage.py migrate #apply the South migration file
> >
> > In the future you'll only need to do steps 2 - 4.
> >
> > You can also do a datamigration so that, for example, you can do a
> > schemamigration, move/change some data, then another schemamigration to
> > clean up orphaned fields or whatever.
> >
> > There's also a south-users mailing list on Google Groups.
> >
> > Shawn
>
> --
> 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.
>
>


-- 
AJ

-- 
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: How change field to "unique" in existing mysql database?

2011-05-14 Thread Chris Seberino
Shawn

Thanks!  Is South just a script that runs?  Can I uninstall after the
conversion if desired?

Or, does it permanently alter a Django app somehow?

cs

On May 14, 10:53 pm, Shawn Milochik  wrote:
> The best way is to use South.
>
> http://south.aeracode.org/
>
> In your current situation, after you install South (pip install then add
> to INSTALLED_APPS, and syncdb to add the South table) you'll just have
> to do this:
>
>      1. manage.py convert_to_south appname #this will set up the basics,
> you'll only do this once
>
>      2. change your model #it should not have changed since the initial
> syncdb until this point
>
>      3. manage.py schemamigration appname name_your_migration --auto
> #create a South migration file
>
>      4. manage.py migrate #apply the South migration file
>
> In the future you'll only need to do steps 2 - 4.
>
> You can also do a datamigration so that, for example, you can do a
> schemamigration, move/change some data, then another schemamigration to
> clean up orphaned fields or whatever.
>
> There's also a south-users mailing list on Google Groups.
>
> Shawn

-- 
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: [help]django's FloatField can't insert the mysql's double type data.

2011-05-14 Thread Karen Tracey
On Sat, May 14, 2011 at 9:10 PM, Korobase  wrote:

>
>
> 2011/5/15 Andy McKay 
>
>>
>> > Exception Type: TypeError at /admin/main/learndjango/add/
>> > Exception Value: 'float' object is not callable
>>
>>
>> Please paste your model that is having the problem.
>>
>
> class MyItem(models.Model):
> title=models.CharField(max_length=1024)
> description=models.CharField(max_length=1024)
> price=models.FloatField(default=0.0)
> time=models.DateTimeField()
> name=models.CharField(max_length=256)
> detail=models.CharField(max_length=1024)
> address_city=models.CharField(max_length=36)
> address_area=models.CharField(max_length=36)
>
>
> def __unicode__(self):
> return self.title
>
> and the ModelAdmin:
>
> class MyItemAdmin(admin.ModelAdmin):
> list_display=('name','title','price','address_city',)
>
> admin.site.register(MyItem, MyItemAdmin)
>
>
>
The traceback indicates that the new object being added is not an instance
of MyItem, but rather a simple float. How that has happened is a mystery; it
is not due to anything you have posted so far. If you cut-and-paste just the
model and model admin definitions you show here into a new 1.3 project, the
admin works fine to add items. There is something more to your code that you
have not shown yet that is causing the problem. Really, Django can insert
float data into a MySQL table (although as Andy notes, using a float field
for something named "price" is likely really really really not what you want
to be doing.

Karen
-- 
http://tracey.org/kmt/

-- 
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: Inverted checkbox value in modelForm field for BooleanField?

2011-05-14 Thread Andy McKay

On 2011-05-14, at 6:08 PM, br wrote:
> However, come interface tweaking time (now), we decided we want to
> display a page with a check box "Auto Cycle?" instead of "click-
> through", so I basically need to invert the actual value with respect
> to this interface .
> What is the easiest way to implement this?

You can access the field and initial data inside the form init and do anything 
you want there. Which depends upon how you are calling your Model form. If you 
are passing through an instance, for example, you could tweak it:

class MyForm(ModelForm):
  def __init__(self, *args, **kw):
kw['instance'].click_through = True
super(MyForm, self).__init__()

--
  Andy McKay
  a...@clearwind.ca
  twitter: @andymckay
 

-- 
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: How change field to "unique" in existing mysql database?

2011-05-14 Thread Shawn Milochik

The best way is to use South.

http://south.aeracode.org/

In your current situation, after you install South (pip install then add 
to INSTALLED_APPS, and syncdb to add the South table) you'll just have 
to do this:


1. manage.py convert_to_south appname #this will set up the basics, 
you'll only do this once


2. change your model #it should not have changed since the initial 
syncdb until this point


3. manage.py schemamigration appname name_your_migration --auto 
#create a South migration file


4. manage.py migrate #apply the South migration file

In the future you'll only need to do steps 2 - 4.

You can also do a datamigration so that, for example, you can do a 
schemamigration, move/change some data, then another schemamigration to 
clean up orphaned fields or whatever.


There's also a south-users mailing list on Google Groups.

Shawn


--
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: Problems importing model classes that reference each other...

2011-05-14 Thread Shawn Milochik
If you have two models that need to explicitly refer to each other then 
they should probably be in the same app.


If they need to be in two apps, you can have a foreign key in one and 
from the other use the RelatedManager to access the first.


You'll have to make these decisions based upon what your app(s) will be 
doing. If one set of functionality can be completely isolated so that 
someone could maybe use it in other projects, then it should be a 
separate app. Then maybe your other app can use resources from that app, 
but it shouldn't be a two-way conversation. Another possibility is that 
both apps are isolated, and a third app with no models of its own has 
the views that actually run your site.


Play with it, draw some pictures, and figure out what the relationships 
really are. And if you decide to experiment, you can always use South to 
migrate your schema and data so your project can evolve as you learn 
more about it.


Shawn

South:
http://south.aeracode.org/

--
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.



How change field to "unique" in existing mysql database?

2011-05-14 Thread Chris Seberino
I have a typical Django app using MySQL.

I've decided to change a model and make some fields unique=True
AFTER tables and data exist in MySQL.

I noticed that "python manage.py syncdb" doesn't automatically modify
MySQL
database to make desired fields unique now.

Is there some MySQL command line equivalent?
Preferably there is a way to do this from Django shell or other way?

Sincerely,

Chris

-- 
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.



Problems importing model classes that reference each other...

2011-05-14 Thread Contoured Solutions
I am trying to create a simple billing/CRM app for my company. I have
create a Django project with the following apps:

sales_manager
office_manager
customer_manager

Within, I have models representing things like Customers, Contacts,
Projects, Tasks, etc. The problem I am having seems to arise from the
fact that I have model classes which reference each other. For
example, the customer_manager.models.py file starts like this:



from sales_manager.models import Contact

# Create your models here.

class Customer(models.Model):
"""
Customer class.

Model code: 'cu'
"""

cu_createdOn = models.DateTimeField('Created On',
auto_now_add=True)
cu_modifiedOn = models.DateTimeField('Last Modified
On',auto_now=True)
cu_lastAccessed = models.DateTimeField('Last Accessed
On',auto_now=True)
cu_active = models.BooleanField('Active', default=True)
...
cu_contacts = models.ManyToManyField(Contact,
verbose_name='Additional Contacts', null=True, blank=True)
cu_comments = models.TextField('Comments', null=True, blank=True)




And my sales_manager.models.py file starts like this:




from customer_manager.models import Customer

# Create your models here.


class Contact(models.Model):
"""
Contact class. Generic container for contacts of all kinds

Model code: 'ct'
"""

ct_createdOn = models.DateTimeField('Created On',
auto_now_add=True)
ct_modifiedOn = models.DateTimeField('Last Modified
On',auto_now=True)
ct_lastAccessed = models.DateTimeField('Last Accessed
On',auto_now=True)
ct_name = models.CharField('Name', max_length=64, null=True,
blank=True)
ct_email = models.EmailField('Email', null=True, blank=True)
...

The models class in the sales_manager.models imports Customer from
customer_manager.models and customer_manager.models imports Contact
from sales_manager.models. All of the model definitions appear okay,
but when I try to execute the syncdb command, I get import errors:


File "C:\Users\dave\Documents\django\my_it_office\..\my_it_office
\office_manager\models.py", line 2, in 
from customer_manager.models import Customer
  File "C:\Users\dave\Documents\django\my_it_office\customer_manager
\models.py", line 2, in 
from sales_manager.models import Contact
  File "C:\Users\dave\Documents\django\my_it_office\sales_manager
\models.py", line 2, in 
from office_manager.models import Staff
  File "C:\Users\dave\Documents\django\my_it_office\office_manager
\models.py", line 2, in 
from customer_manager.models import Customer
ImportError: cannot import name Customer



How can I get around this? I would like to keep those models in
separate apps, but I also need for those apps to reference each others
models. Can someone help shed some light on this? I am looking at it
the wrong way?

-- 
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: [help]django's FloatField can't insert the mysql's double type data.

2011-05-14 Thread Andy McKay

On 2011-05-14, at 6:10 PM, Korobase wrote:
> price=models.FloatField(default=0.0)

You really should really be using a DecimalField for storing prices, not a 
FloatField.

http://docs.djangoproject.com/en/dev/ref/models/fields/#decimalfield
http://docs.djangoproject.com/en/dev/ref/models/fields/#floatfield

Not sure off the top of my head why you get that error though.
--
  Andy McKay
  a...@clearwind.ca
  twitter: @andymckay
 

-- 
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: [help]django's FloatField can't insert the mysql's double type data.

2011-05-14 Thread Korobase
2011/5/15 Andy McKay 

>
> > Exception Type: TypeError at /admin/main/learndjango/add/
> > Exception Value: 'float' object is not callable
>
>
> Please paste your model that is having the problem.
>

class MyItem(models.Model):
title=models.CharField(max_length=1024)
description=models.CharField(max_length=1024)
price=models.FloatField(default=0.0)
time=models.DateTimeField()
name=models.CharField(max_length=256)
detail=models.CharField(max_length=1024)
address_city=models.CharField(max_length=36)
address_area=models.CharField(max_length=36)


def __unicode__(self):
return self.title

and the ModelAdmin:

class MyItemAdmin(admin.ModelAdmin):
list_display=('name','title','price','address_city',)

admin.site.register(MyItem, MyItemAdmin)

Thanks.


> --
>  Andy McKay
>  a...@clearwind.ca
>  twitter: @andymckay
>
>
> --
> 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.
>
>


--

-- 
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.



Inverted checkbox value in modelForm field for BooleanField?

2011-05-14 Thread br
Conceptually, an interface element of my application can either be
click through (i.e. requires user interaction) or auto-cycle (no user
interaction).  So its boolean.  But i picked the wrong one when I
originally designed the model and now we have existing data and I
don't want to change it.

So I have a database field

class MyModel(Model):
 click_through = models.BooleanField(
 . . . )

And a modelform:

class MyForm(ModelForm):

class Meta:
model = MyModel
fields = ('name', 'click_through')

However, come interface tweaking time (now), we decided we want to
display a page with a check box "Auto Cycle?" instead of "click-
through", so I basically need to invert the actual value with respect
to this interface .

What is the easiest way to implement this?

I realize i could create a custom Field class and override to_python
to invert the value after the Form is submitted, but how about
inverting the value after i initiall load an instance of the value and
before it goes into the form, so that it displays a checked box if
click-through is False and vice-versa?  Is there an override similar
to to_python for this, or is there another way of going about it?


Thanks,

Ben

-- 
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: ajax select box

2011-05-14 Thread gusheng
i've written something similar to Dajax..
but i don't think that's a good solution..
and i'll not use it in my new project..

it goes the opposite of django philosophy..to design url explicitly..
url should be well mantained..
..and can be used as an api..as similar as possible
i thought..

On 5月9日, 上午2时22分, Ogi Vranesic  wrote:
> Hallo
>
> You can use Dajax(ice) to solve your issue.
> First Dajax and Dajaxice must be installed.
> In your select box for countries add event 'onchange' i.e.:
> onchange="Dajaxice.ajax.getCitiesByCountry('Dajax.process', {'name':this.name,
> 'value':this.value})">
> According to this example you must have the file ajax.py and the function
> getCitiesByCountry must be registered in settings.py like:
> DAJAXICE_FUNCTIONS = (
> 'ajax.getCitiesByCountry',
> )
>
> Afterwards define the function getCitiesByCountry in ajax module
> where you can generate options for cities using python and replace them
> automatically in html.
>
> If something is not clear google for Dajax, Dajaxice, dajax.json()
>
> Greetings
> Ogi
>
> On Sonntag 08 Mai 2011 06:46:54 pm you wrote:
>
>
>
>
>
>
>
> > but i dont know about jquery or ajax, can i get any example from any
> > site , can u provide any link which has such code written
>
> > On May 7, 12:10 pm, Shawn Milochik  wrote:
> > > You'll need to write JavaScript.
>
> > > Specifically:
>
> > >  Write a function that uses AJAX to pass the state to a Django view
> > > and receive the city list, then populate the city drop-down.
>
> > >  Bind that function to the change event of your state drop-down box.
>
> > > This isn't a Django question, though. If you have trouble doing that try
> > > a JavaScript mailing list.
>
> > > I recommend using jQuery's .ajax() function for this.
>
> > > Shawn

-- 
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: existing data failing validation

2011-05-14 Thread Shawn Milochik

On 05/14/2011 08:09 PM, Greg Donald wrote:


I have

from django.db import models
from django.forms import ModelForm

class Contact( models.Model ):
 company = models.ForeignKey( Company )
 name = models.CharField( max_length=32 )

class ContactForm( ModelForm ):
 class Meta:
 model = Contact
 name = CharField( required=True )

The fields failing validation are ones I'm not re-submitting back in
my edit form.  Am I supposed to list company again in my ContactForm
class?  Guess I can go try it.




That 'name = Charfield' doesn't belong there at all.

Replace that line with this:
exclude = ['company']

If you did want to add extra fields to a ModelForm you'd put them at the 
top -- the same place as you would in a Form. Just FYI -- you don't need 
one here.


Shawn

--
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: existing data failing validation

2011-05-14 Thread Greg Donald
On Sat, May 14, 2011 at 6:56 PM, Shawn Milochik  wrote:
> If you're using forms.Form objects instead of forms.ModelForm objects then
> that would explain it. If you're dealing with a model then you should
> probably be using a ModelForm.
>
> To have a ModelForm that doesn't show certain fields just add a Meta section
> and set the field names in an iterable named 'exclude'.

I have

from django.db import models
from django.forms import ModelForm

class Contact( models.Model ):
company = models.ForeignKey( Company )
name = models.CharField( max_length=32 )

class ContactForm( ModelForm ):
class Meta:
model = Contact
name = CharField( required=True )

The fields failing validation are ones I'm not re-submitting back in
my edit form.  Am I supposed to list company again in my ContactForm
class?  Guess I can go try it.


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: MEDIA and STATIC in a nutshell?

2011-05-14 Thread Shawn Milochik

Eiji,

Sorry to hear about the Japanese translation being out-of-date. I just 
checked and saw that it's extremely old. The development of Django moves 
too quickly to rely on static documentation. I don't know of any 
alternatives to the English version if you want to remain current, but 
in any case your English is very good, so at least you should be able to 
get by, and this list is usually a big help.


Shawn


--
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: existing data failing validation

2011-05-14 Thread Shawn Milochik

On 05/14/2011 07:51 PM, Greg Donald wrote:

How does one handle non-changing existing data when updating a form?

My 'add' form includes several fields my 'edit' form does not.  For
example once I create a contact and assign it a company_id foreign
key, it will never change.  So when I implement my edit method in my
view, I get errors about not providing fields already set.

form = ContactForm( request.POST, instance=contact )

form.errors says I need to provide a company, but it is already saved
in the database.

What am I missing here?




If you're using forms.Form objects instead of forms.ModelForm objects 
then that would explain it. If you're dealing with a model then you 
should probably be using a ModelForm.


To have a ModelForm that doesn't show certain fields just add a Meta 
section and set the field names in an iterable named 'exclude'.



--
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: form new versus edit

2011-05-14 Thread br
My HTML guy and designer tend to get together to do some fancy stuff
(read: pain in the butt) so sometimes I need to access the data that a
model form field represents and can't just let django render it, which
is obviously the preferred way and I go that way if possible.  I am
pretty knew to this, but i figured that a custom tag filter could do
the trick, given that the data is in different places for an unbound
model form vs a form that is bound.  (would be a nice feature to have
one variable or attribute to access that would always have it, but
there seems to be resistance to this.)  This seems to work for my use
cases, but I haven't tested extensively so use at your own risk and
YMMV.  (put this in a python file in a templatetags directory in your
app and make sure you load the tags . . .read the docs)

@register.filter(name='modelform_field_value')
def modelform_field_value(value, arg):
"""
Usage: | model_field_value : ""
Returns the value of a field in a ModelForm, regardless of whether
the ModelForm was loaded with a Model Instance or with POST data
"""

form = value
field_name = arg
try:
if form.data.get(field_name) != None:
return  getattr(form.data, field_name)
# post data takes priority over instance data (this is useful
when is_valid is false and a form is returned to the template for
errors to be displayed, wherein both form and instance exist, but the
post is the most recent)
else:
return getattr(form.instance, field_name)
except Exception as e:
logger.error("Error in modelform_field_value tag.  Unable to
get value for field %s in form %s. \n%s"  %(field_name, form, str(e))
return "" # Best to log the error and display nothing than
letting the server throw a 500 or putting up something incorrect.

As far as getting the id in a hidden field,

you can use something like when you define your form:

class MyForm:

class Meta:
model = MyModel
fields = ('id', )
widgets = {
  'id': HiddenInput(),
 
}

or you could do something like this:

id  = IntegerField(
   widget = HiddenInput (attrs = {'class':'some-
class'}))


My experience has been that working with forms was the most
challenging part of Django to learn, decipher and figure out,
particularly if you don't want to let django render forms in a
default, simple way, which if you're working with Web 2.0 mentality
designers, where everything is "ajaxy", is rarely the case.  But after
learning enough to make django forms work for me with their designs, i
highly recommend defining your fields on the django side, because it
makes all of the backend stuff: processing, validation, writing to db,
etc. etc.  so so much easier and less error prone.  I typically only
use the above tag if i am just rendering some static text or anchor
tag, or checking if a value exists or equals something in template tag
logic. If its a form element, i try to define it in django.

Ben


On May 14, 4:45 pm, Greg Donald  wrote:
> On Sat, May 14, 2011 at 5:20 PM, Shawn Milochik  wrote:
> > One way:
>
> > class CustomCharField(forms.CharField):
>
> >     def __init__(self, *args, **kwargs):
>
> >     super(CustomCharField, self).__init__(*args, **kwargs)
>
> >     self.widget=forms.TextInput(attrs={ 'class':'myclass' })
>
> > class MyForm(forms.Form):
>
> >     field1 = forms.CustomCharField()
> >     field2 = forms.CustomCharField()
>
> Thank you.
>
> What is the convention for getting a pk id into a hidden form field?
>
> Since {{ form.name }} is the convention for getting my name field HTML
> rendered, I naturally tried {{ form.id }}, but it doesn't seem to know
> about Django conventions I don't guess.
>
> --
> Greg Donald
> destiney.com | gregdonald.com

-- 
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.



existing data failing validation

2011-05-14 Thread Greg Donald
How does one handle non-changing existing data when updating a form?

My 'add' form includes several fields my 'edit' form does not.  For
example once I create a contact and assign it a company_id foreign
key, it will never change.  So when I implement my edit method in my
view, I get errors about not providing fields already set.

form = ContactForm( request.POST, instance=contact )

form.errors says I need to provide a company, but it is already saved
in the database.

What am I missing here?


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: MEDIA and STATIC in a nutshell?

2011-05-14 Thread Shawn Milochik

Eiji,

If you put a folder in each app named 'static' it will automatically be 
used when you run 'manage.py collectstatic.'


You only need to specify additional directories if you want to pull 
static media from somewhere else, of if you named your static folders 
something other than 'static' in your apps.


Shawn


--
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: Am I over-normalizing?

2011-05-14 Thread Shawn Milochik

On 05/14/2011 06:50 PM, bendavis78 wrote:

I have a database of patients ("Patient" model), and a patient can
have subordinate accounts which is a self-foreign-key (eg, for family
members),  We also store multiple addresses for each patient (home,
work, billing).   I'm pretty sure I need to have an Address model as a
many-to-one, because a patient can have multiple addresses.  But, I'm
also thinking of going one more step and making it a many-to-many,
because multiple patients (eg, a family) can share the same address.
Am I over-normalizing if I do this?  It seems that it would make
editing via the admin a bit more difficult,  however the data would
not be duplicated.  Is there a good rule-of-thumb for these kind of
design decisions?

The right answer depends on what you are actually going to need to do 
with the data.


I think that it's better not to have multiple people share the same 
address, for the simple reason that one of them may move, or change 
something about the address which would affect the others.


There might be a decent case for storing relationships so that, for 
example, you know that people are related.


Also, if you expect to be doing much with many-to-many relationships, 
definitely check out the docs for instructions on how to define your own 
relationship tables so you can store additional data that really doesn't 
belong elsewhere.

http://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-on-many-to-many-relationships

Shawn

--
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.



Am I over-normalizing?

2011-05-14 Thread bendavis78
I have a database of patients ("Patient" model), and a patient can
have subordinate accounts which is a self-foreign-key (eg, for family
members),  We also store multiple addresses for each patient (home,
work, billing).   I'm pretty sure I need to have an Address model as a
many-to-one, because a patient can have multiple addresses.  But, I'm
also thinking of going one more step and making it a many-to-many,
because multiple patients (eg, a family) can share the same address.
Am I over-normalizing if I do this?  It seems that it would make
editing via the admin a bit more difficult,  however the data would
not be duplicated.  Is there a good rule-of-thumb for these kind of
design decisions?

-- 
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: MEDIA and STATIC in a nutshell?

2011-05-14 Thread Eiji Kobayashi
Thanks Shawn, I didn't read the documentation as thoroughly as I should
have. And I know that I should read the English version rather than relying
on the outdated, Japanese version. But this is good, as I need to learn
English more.

I modified the urls.py according to the docs, and the MEDIA_URL, MEDIA_ROOT
work now.

Just one more question, if I can...

Now, the MEDIA_* variables work fine using adding a url pattern, but how can
I serve the STATIC_* variables without the need to define the
STATICFILES_DIRS variables. I've tried just relying on the STATIC_URL and
STATIC_ROOT variables and they do not work.

I tried all the examples in the (English) documentation, and they don't
work. I must be missing something here.

Thanks,

Eiji

On Sat, May 14, 2011 at 10:31 AM, Shawn Milochik  wrote:

> It sounds like all your issues with these features are a result of not
> reading the documentation.
>
> Feel free to ignore these optional features and do things the hard way if
> you feel like it.
>
> On the other hand, you could invest a small amount of time in understanding
> them and get the benefits.
>
> Here's one small example of something both of you are complaining about
> only because you don't understand it.
>
> http://docs.djangoproject.com/en/1.3/howto/static-files/#serving-static-files-in-development
>
>
>
> --
> 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.
>
>

-- 
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: form new versus edit

2011-05-14 Thread Greg Donald
On Sat, May 14, 2011 at 5:20 PM, Shawn Milochik  wrote:
> One way:
>
> class CustomCharField(forms.CharField):
>
>     def __init__(self, *args, **kwargs):
>
>     super(CustomCharField, self).__init__(*args, **kwargs)
>
>     self.widget=forms.TextInput(attrs={ 'class':'myclass' })
>
>
> class MyForm(forms.Form):
>
>     field1 = forms.CustomCharField()
>     field2 = forms.CustomCharField()


Thank you.

What is the convention for getting a pk id into a hidden form field?

Since {{ form.name }} is the convention for getting my name field HTML
rendered, I naturally tried {{ form.id }}, but it doesn't seem to know
about Django conventions I don't guess.


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: form new versus edit

2011-05-14 Thread Shawn Milochik

On 05/14/2011 06:09 PM, Greg Donald wrote:

 On Sat, May 14, 2011 at 4:58 PM, Shawn Milochik 
 wrote:
> This isn't a case of "our way rules and if you disagree then you
> suck." I just wanted to make sure you don't walk away with that
> impression.


 How can I set this same widget value

 name = CharField( widget=TextInput( attrs={ 'class':'myclass' } ) )

 in a single place for all my CharField types?





One way:


class CustomCharField(forms.CharField):

def __init__(self, *args, **kwargs):

super(CustomCharField, self).__init__(*args, **kwargs)

self.widget=forms.TextInput(attrs={ 'class':'myclass' })


class MyForm(forms.Form):

field1 = forms.CustomCharField()
field2 = forms.CustomCharField()



--
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: form new versus edit

2011-05-14 Thread Greg Donald
On Sat, May 14, 2011 at 4:58 PM, Shawn Milochik  wrote:
> This isn't a case of "our way rules and if you disagree then you suck." I
> just wanted to make sure you don't walk away with that impression.


How can I set this same widget value

name = CharField( widget=TextInput( attrs={ 'class':'myclass' } ) )

in a single place for all my CharField types?



-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: form new versus edit

2011-05-14 Thread Shawn Milochik

On 05/14/2011 05:47 PM, Greg Donald wrote:

On Sat, May 14, 2011 at 4:39 PM, Shawn Milochik  wrote:

I'm certain there are plenty of reasons that others could chime in with. In
any case, you're free to do it however you like. But if you choose to use
Django, be aware of the fact that a huge amount of thought has gone into the
project, and if something's there it's probably for a really good reason.
When you choose not to follow a Django convention and run into a problem
then don't be surprised.

I didn't realize trying to access my own form data directly was
unconventional, my bad.



Again, if there's anything you want to do that you can't because of the 
way something in Django works, just ask.


The whole point of a Web framework is to save you (the developer) the 
hassle of doing all the routine junk, such as validating/sanitizing 
input, re-drawing forms with errors for user correction, writing SQL, 
etc. It's always good to know how it's working and have the ability to 
tweak it, as you obviously do. But as long as you have that to fall back 
on it's best to let Django do the heavy (or boring) lifting for you 
whenever possible.


This isn't a case of "our way rules and if you disagree then you suck." 
I just wanted to make sure you don't walk away with that impression.


Shawn


--
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: form new versus edit

2011-05-14 Thread Greg Donald
On Sat, May 14, 2011 at 4:39 PM, Shawn Milochik  wrote:
> I'm certain there are plenty of reasons that others could chime in with. In
> any case, you're free to do it however you like. But if you choose to use
> Django, be aware of the fact that a huge amount of thought has gone into the
> project, and if something's there it's probably for a really good reason.
> When you choose not to follow a Django convention and run into a problem
> then don't be surprised.

I didn't realize trying to access my own form data directly was
unconventional, my bad.


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: form new versus edit

2011-05-14 Thread Shawn Milochik

On 05/14/2011 05:33 PM, Greg Donald wrote:

On Sat, May 14, 2011 at 4:22 PM, Daniel Roseman  wrote:

Which is what Shawn said. If you follow the pattern described in the
excellent documentation, you'll see that there's no reason to try and
reference the form's data, as the form will re-render itself anyway if
validation fails. And there's no reason to have separate templates or views
for add and edit.

So the fact that form.name.data is set sometimes but not others is not
a bug?  Seems like a bug to me.  Why is it set at all if accessing it
isn't the preferred way?

So OK, if I do use {{ form.name }} then I have to set CSS attributes
for every field using:

name = forms.CharField( widget=forms.TextInput(attrs={'class':'special'}))

How is that better than just writing a simple  field myself?


There are a lot of benefits, beginning with the fact that doing it once 
in your Form class is a lot better than doing it in each template.


Secondly, if you ever use a prefix with your form or use a formset, then 
writing your own raw HTML elements is going to bite you hard.


I'm certain there are plenty of reasons that others could chime in with. 
In any case, you're free to do it however you like. But if you choose to 
use Django, be aware of the fact that a huge amount of thought has gone 
into the project, and if something's there it's probably for a really 
good reason. When you choose not to follow a Django convention and run 
into a problem then don't be surprised.


Shawn


--
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: form new versus edit

2011-05-14 Thread Greg Donald
On Sat, May 14, 2011 at 4:22 PM, Daniel Roseman  wrote:
> Which is what Shawn said. If you follow the pattern described in the
> excellent documentation, you'll see that there's no reason to try and
> reference the form's data, as the form will re-render itself anyway if
> validation fails. And there's no reason to have separate templates or views
> for add and edit.

So the fact that form.name.data is set sometimes but not others is not
a bug?  Seems like a bug to me.  Why is it set at all if accessing it
isn't the preferred way?

So OK, if I do use {{ form.name }} then I have to set CSS attributes
for every field using:

name = forms.CharField( widget=forms.TextInput(attrs={'class':'special'}))

How is that better than just writing a simple  field myself?


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: form new versus edit

2011-05-14 Thread Daniel Roseman

On Saturday, 14 May 2011 22:14:38 UTC+1, Greg Donald wrote:
>
> On Sat, May 14, 2011 at 4:08 PM, Shawn Milochik  
> wrote:
> > The problem is that you're doing this at all. You should instead be using 
> {{
> > form.name }} to put the field in the form.
>
>
> Well that works for the vanilla case but I need access to the data.
>
>
> -- 
> Greg Donald
>
Which is what Shawn said. If you follow the pattern described in the 
excellent documentation, you'll see that there's no reason to try and 
reference the form's data, as the form will re-render itself anyway if 
validation fails. And there's no reason to have separate templates or views 
for add and edit.
--
DR.

-- 
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: form new versus edit

2011-05-14 Thread Shawn Milochik

On 05/14/2011 05:14 PM, Greg Donald wrote:

On Sat, May 14, 2011 at 4:08 PM, Shawn Milochik  wrote:

On 05/14/2011 05:04 PM, Greg Donald wrote:

I have a "new" contact form.  If I post it, and it has error, I found
(while debugging, not documented that I can find) that I can redraw
the submitted form data using form.name.data like this:





The problem is that you're doing this at all. You should instead be using {{
form.name }} to put the field in the form.


Well that works for the vanilla case but I need access to the data.



What do you need to do that this makes difficult?

--
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: form new versus edit

2011-05-14 Thread Greg Donald
On Sat, May 14, 2011 at 4:08 PM, Shawn Milochik  wrote:
> On 05/14/2011 05:04 PM, Greg Donald wrote:
>>
>> I have a "new" contact form.  If I post it, and it has error, I found
>> (while debugging, not documented that I can find) that I can redraw
>> the submitted form data using form.name.data like this:
>>
>> 
>
> 
>
> The problem is that you're doing this at all. You should instead be using {{
> form.name }} to put the field in the form.


Well that works for the vanilla case but I need access to the data.


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: form new versus edit

2011-05-14 Thread Shawn Milochik

On 05/14/2011 05:04 PM, Greg Donald wrote:

I have a "new" contact form.  If I post it, and it has error, I found
(while debugging, not documented that I can find) that I can redraw
the submitted form data using form.name.data like this:





The problem is that you're doing this at all. You should instead be 
using {{ form.name }} to put the field in the form.


This will work in either case.

--
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.



form new versus edit

2011-05-14 Thread Greg Donald
I have a "new" contact form.  If I post it, and it has error, I found
(while debugging, not documented that I can find) that I can redraw
the submitted form data using form.name.data like this:



But, if I use that same form model in my "edit" contact form,
form.name.data is None.  Why is that?


In my new method I do:

form = ContactForm( request.POST )


In my edit method I do:

contact = Contact.objects.get( pk=id )
form = ContactForm( instance=contact )

But then the form contains none of the fields I'm expecting, form.name
simply isn't there so form.name.data throws an exception.


What am I doing wrong?

I'd really like to just have my one _form.html template included in
both my add.html and my edit.html templates.  How can I do that when
the form doesn't even work the same between new versus editing?


Thanks.


-- 
Greg Donald
destiney.com | gregdonald.com

-- 
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: Django app models

2011-05-14 Thread Shawn Milochik

On 05/14/2011 04:25 PM, augdawg wrote:

I can add it to my PYTHONPATH by doing 'export PYTHONPATH=""'
right?



Yes, but you might want to just append it to your PYTHONPATH, in case 
there's already something there you don't want to lose.


Like this:

export PYTHONPATH=$PYTHONPATH;

Maybe even put the new one first, if you expect a naming conflict.



--
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: Django app models

2011-05-14 Thread augdawg
I can add it to my PYTHONPATH by doing 'export PYTHONPATH=""'
right?

-- 
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: Django app models

2011-05-14 Thread Shawn Milochik
All you should need is for the external app to be somewhere on your 
PYTHONPATH.


Then you can add it to INSTALLED_APPS in settings.py and you'll be all set.


--
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.



Django app models

2011-05-14 Thread augdawg
Hey all,
I have a Django project where I need to access another apps models.
The problem is that I cannot directly import the model that I need
from the app that needs to access it (I'm pretty sure that I need it
for a ForeignKey field or similar). Is there any way that I can fix
this besides moving the file that needs to access it to a higher spot
on the filesystem?

Thanks in advance.

-- 
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: How to choose a license for an app or a project?

2011-05-14 Thread Boštjan Mejak
Say I create an app in Python and wxPython (a Python GUI framework). And
then I upload my installation binaries (binaries created with py2exe and
setup made with Inno Setup) to, say, Google Code. I don't want to dislose my
source code. I just want my users to download the setup program and use my
program at their will. What license would you give in such a case? And also,
where would you put the license? Would you, in this particular case, even
give a license?

-- 
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: How to choose a license for an app or a project?

2011-05-14 Thread Bjarni Rúnar Einarsson
Hi Bostjan,

I think you are misunderstanding one basic thing. You do not NEED a license
for your own code.  By default, program code is protected by copyright in
most parts of the world.

Licenses clarify or renounce some or all of the protections of copyright and
patent law, and they only matter if or when you share your code with
others.  If your code is for your use only, or internal to your company, you
do not need a license for it.

The AGPL is the only exception: if you are modifying someone else's AGPL
code, you may possibly need to disclose your changes.  It depends on what
you are doing.  Otherwise, all the license allow you to keep things private,
and you do not really need a license at all for your own original
inventions.


On Sat, May 14, 2011 at 9:37 AM, Boštjan Mejak wrote:

> So if I use the BSD license as Django does, do I need to (according to this
> license) disclose my source code or not? Which BSD license is Django using
> anyway? Clause 3?
>
> --
> 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.
>



-- 
Bjarni R. Einarsson
The Beanstalks Project ehf.

Making personal web-pages fly: http://pagekite.net/

-- 
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: How to choose a license for an app or a project?

2011-05-14 Thread Bjarni Rúnar Einarsson
On Sat, May 14, 2011 at 1:38 AM, Kenneth Gonsalves
wrote:

> On Fri, 2011-05-13 at 12:23 +, Bjarni Rúnar Einarsson wrote:
> > Other random points: Generally speaking, I prefer the more recent,
> > modern
> > licenses (GPLv3 instead of GPLv2, Apache instead of BSD) because they
> > do a
> > better job covering issues like patents.  Some would argue that
> > putting
> > things in the public domain is "dangerous" because it doesn't
> > explicitly
> > disclaim liability.
>
> django itself uses the BSD license as do the majority of developers of
> third party apps - django is doing well.
>

Yeah, so by default django apps would fall under my rule-of-thumb #3: do
what your community does. :-)

-- 
Bjarni R. Einarsson
The Beanstalks Project ehf.

Making personal web-pages fly: http://pagekite.net/

-- 
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: MEDIA and STATIC in a nutshell?

2011-05-14 Thread Shawn Milochik
It sounds like all your issues with these features are a result of not 
reading the documentation.


Feel free to ignore these optional features and do things the hard way 
if you feel like it.


On the other hand, you could invest a small amount of time in 
understanding them and get the benefits.


Here's one small example of something both of you are complaining about 
only because you don't understand it.

http://docs.djangoproject.com/en/1.3/howto/static-files/#serving-static-files-in-development


--
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: [help]django's FloatField can't insert the mysql's double type data.

2011-05-14 Thread Andy McKay

> Exception Type: TypeError at /admin/main/learndjango/add/
> Exception Value: 'float' object is not callable


Please paste your model that is having the problem.
--
  Andy McKay
  a...@clearwind.ca
  twitter: @andymckay
 

-- 
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: Built-in login form via inclusion tag

2011-05-14 Thread Gabe
Any advice? Do I have to do new form?

Gabe

On 13 Maj, 14:55, Gabe  wrote:
> Hi,
>
> what I am trying to do is to put a login box which will use
> django.contrib.auth.views.login. According to documentation I`ve
> crated inclusion tag which works, but it only views form sumbit button
> not a whole form. This form is from tutorialand looks like this:
>
> {% load url from future %}
>
> {% block content %}
>
> {% if form.errors %}
> Niepoprawny login lub nazwa u¿ytkownika.
> {% endif %}
>
> 
> {% csrf_token %}
> 
> 
>     {{ form.username.label_tag }}
>     {{ form.username }}
> 
> 
>     {{ form.password.label_tag }}
>     {{ form.password }}
> 
> 
>
> 
> 
> 
>
> {% endblock %}
>
> It seems like it don`t know enything about form variable. How can I
> give it to it via inclusion tag?
>
> best regards
> Gabe

-- 
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.



[help]django's FloatField can't insert the mysql's double type data.

2011-05-14 Thread Korobase
Hi,all!
I use the django admin interface to insert a record to the mysql database,
While the field is FloatField in django and the mysql field show a double
type,
But when I click the save button,it tell me that:

Environment:


Request Method: POST
Request URL: http://localhost:8080/admin/main/learndjango/add/

Django Version: 1.3
Python Version: 2.6.6
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'tuang.main',
 'django.contrib.admin',
 'django.contrib.admindocs']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'learndjango.middleware.GetUserLoactionMiddleware')


Traceback:
File "C:\Python26\lib\site-packages\django\core\handlers\base.py" in
get_response
  111. response = callback(request, *callback_args,
**callback_kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in
wrapper
  307. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in
_wrapped_view
  93. response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\views\decorators\cache.py" in
_wrapped_view_func
  79. response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\sites.py" in inner
  197. return view(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in _wrapper
  28. return bound_func(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in
_wrapped_view
  93. response = view_func(request, *args, **kwargs)
File "C:\Python26\lib\site-packages\django\utils\decorators.py" in
bound_func
  24. return func(self, *args2, **kwargs2)
File "C:\Python26\lib\site-packages\django\db\transaction.py" in inner
  217. res = func(*args, **kwargs)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in
add_view
  882. self.save_model(request, new_object, form,
change=False)
File "C:\Python26\lib\site-packages\django\contrib\admin\options.py" in
save_model
  665. obj.save()

Exception Type: TypeError at /admin/main/learndjango/add/
Exception Value: 'float' object is not callable

Any reply is appreciated.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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



django-jython develop server don't respond

2011-05-14 Thread Amedeo
Hi, I work to a project on my laptop in with I installed django-jython
under Archlinux, and all work correctly.
After some problem with my project, i try to install django-jython
under one other pc in with runs OpenSuse.

I installed jython from the installer in the jython web-site.
I installed and configured postgresql.
I installed django with easy_install django.
I test django with python 2.7 and all work correctly (I make a new
project and run "python manage.py runserver", and see the welcome
page)
I installed django-jython with easy_install.
I update the $JYTHONPATH in the .bashrc with the path of django and
django-jython.
Running
jython
import django
import doj
All is ok.

But, doing the same test that in python:
Create a empty project and run "jython manage.py runserver", i don't
see the welcome page, the server seem don't receive any request; and
so don't respond, looking with wireshark i see that did not start any
request.
Obviously the same problem are with my real project.

Where is the error?

Apparently the configuration is identical to the other pc.

Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06)
OpenJDK Runtime Environment (IcedTea6 1.9.7) (suse-1.2.1-i386)
OpenJDK Server VM (build 19.0-b09, mixed mode)


PS. I'm sorry for my bad English i hope your understand!

-- 
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: Why is request.session.flush() deleting my objects from DB?

2011-05-14 Thread ekms
ok, I spot the bug. In one of these models, I have a foreign key to
Session model.
So, when I do session.flush(), on cascade deleted all the related
models.

thank you for your time.

On May 14, 3:15 pm, ekms  wrote:
> I debugged it step by step and the data dissapears from DB in the line
> of session.flush()
>
> The data are three models that I created, and instances of these
> models are saved in the form. The difference between these models and
> others saved but not deleted by flush(), is that these 3 models have
> foreign keys to User model.
>
> Later, when I arrive at home, I will post the code and models...
>
> On May 14, 4:54 am, Shawn Milochik  wrote:
>
> > Given that logging a user out calls flush(), I don't believe that's
> > what's deleting your data. Otherwise everyone using contrib.auth would
> > be complaining.
>
> > What data is being deleted?
>
>

-- 
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: Why is request.session.flush() deleting my objects from DB?

2011-05-14 Thread ekms
I debugged it step by step and the data dissapears from DB in the line
of session.flush()

The data are three models that I created, and instances of these
models are saved in the form. The difference between these models and
others saved but not deleted by flush(), is that these 3 models have
foreign keys to User model.

Later, when I arrive at home, I will post the code and models...

On May 14, 4:54 am, Shawn Milochik  wrote:
> Given that logging a user out calls flush(), I don't believe that's
> what's deleting your data. Otherwise everyone using contrib.auth would
> be complaining.
>
> What data is being deleted?

-- 
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.



Jinja2 template loader for django

2011-05-14 Thread Alexander Schepanovski
Not a question, just a piece of code. Feel free to use it. And any
feedback will be appreciated.

Starting from Django 1.2 you can create your custom template loader
that returns your Template object. Doing that you can make django's
render_to_response, render_to_string and counterparts render using
your template system.

I came up with this one: https://gist.github.com/972162
It loads Jinja2 templates transparently and falls back to Django
templates for admin, contrib and third-party apps.

And yes, I know about coffin I just don't like it's idea. I prefer
using Jinja2 templates their way and don't litter them with django
concepts such as template tags.

-- 
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: How to choose a license for an app or a project?

2011-05-14 Thread Boštjan Mejak
So if I use the BSD license as Django does, do I need to (according to this
license) disclose my source code or not? Which BSD license is Django using
anyway? Clause 3?

-- 
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: MEDIA and STATIC in a nutshell?

2011-05-14 Thread Eiji Kobayashi
Exactly.

Perhaps we should just ignore MEDIA and STATIC variable setup in the
settings file altogether. When I couldn't get the variables to work like how
I thought they should work, I just put the following stuff in the Apache
vhost config file:

Alias /media /Users/eiji/Sites/assets/media
Alias /static /Users/eiji/Sites/assets/static
Alias /admin/media/
/Library/Python/2.6/site-packages/django/contrib/admin/media/

But the problem is then I have to always use Apache even during development,
and I can't use Django's built-in web server.

It seems very repetitive to have to set:
MEDIA_ROOT = '/path/to/mymedia'
MEDIA_URL = '/media/'
in the settings file, then add almost the same thing to the Apache conf
file, and, in the case of STATIC, I also have to set the STATICFILES_DIRS
again with almost the same things.

Hmmm...

Eiji

On Fri, May 13, 2011 at 11:21 PM, km  wrote:

> Hi,
>
> On Sat, May 14, 2011 at 10:24 AM, Shawn Milochik wrote:
>
>> Did you read the docs?
>> http://docs.djangoproject.com/en/1.3/ref/contrib/staticfiles/
>>
>> To use the staticfiles app you need to not only put the right things in
>> settings.py, but also run manage.py collectstatic to gather up all your
>> static content, then rsync/copy/whatever that content to the proper location
>> on your server so that the stuff you put in settings.py is valid.
>>
>> Same thing for media, to some extent (no 'collectstatic' analog). Django's
>> not going to serve your media or your static content in production. That's
>> going to be up to your Web server (Apache/nginx/lighttpd/whatever), and
>> setting that up properly is your job. It's way outside of the scope of
>> Django to do this for you.
>>
>> If django is not going to serve media in production and we totally depend
> on webserver to do that then what is the point in having variables such as
> MEDIA  and STATIC ?
>
> Probably, one can setup -static media- on the webserver which could be
> accessed as www.url/media and thus refer to this relative path as /media in
> templates instead of {{MEDIA}} or {{STATIC}}; which is much simpler than
> meddling with STATIC or MEDIA variables. Isnt it ?
>
> KM
>
>>
>>
>> --
>> 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.
>>
>>
>  --
> 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.
>

-- 
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.