Re: Django form show initial prepopulate on edit

2010-10-27 Thread Hudar
Hi,

Yes, because i use appengine, so django model not supported.

Btw i fixed the problem , by using {{ postForm.category }} instead,
and put the css class by define

category = forms.CharField(widget =
forms.TextInput(attrs={'class':'somecssclass'})   instead of wrote it
in html.

Thanks.

On Oct 28, 12:26 am, Daniel Roseman  wrote:
> On Oct 27, 3:25 pm, Hudar  wrote:
>
>
>
> > Hi,
>
> > Just wondering, how we could show initial value on the edit form. Let
> > say we have code like this to retrive the data ;
>
> > if request.method == 'GET':
> >     post = models.Post.get_by_key_name(key_name)
> >     editPostForm = postform.PostForm(initial={
> >                           'title': post.title,
> >                           'body': post.body,
> >                           'category': post.category,
> >                           'tags': ' '.join(post.tags)})
>
> >     return render_to_response('admin/newpost.html', {
> >                              'postForm':editPostForm,
> >                              'action':post.get_edit_url(),})
>
> > but when i code the form like this :
> >  > name="category" max_length="30"
> > value="{% if postForm.category.data %}{{ postForm.category.data }}{%
> > endif %}">
>
> > it doesnt show up the initial category in the textfield. Please help,
> > thanks
>
> You probably need to use post.category.id in your initial dictionary.
>
> However, you would be better off using a ModelForm, and passing
> 'instance' rather than 'initial'.
> --
> 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-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 erest interfac

2010-10-27 Thread sami nathan
hi for django restfull interface i am using the link given below is it
correct i am experiencing error in that steps
http://code.google.com/p/django-restful-model-views/ please visit this
and tell me

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



Using localflavor with admin?

2010-10-27 Thread Victor Hooi
Hi,

Is there any way to combine the localflavor module (http://
docs.djangoproject.com/en/dev/ref/contrib/localflavor/) with Django's
in-built admin module?

For example, I'd like to create a model with say, a Postcode and phone-
number field, and have these validated in the admin, as per the rules
setup in localflavor?

Cheers,
Victor

-- 
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: Multiple database issue v1.2.3 - Django reading the wrong database

2010-10-27 Thread Russell Keith-Magee
On Wed, Oct 27, 2010 at 1:13 AM, Stodge  wrote:
> I have two PostgreSQL (postgresql_psycopg2) databases defined in my
> settings; default and scenes.
>
> If I perform a filter using the 'scenes' DB I get the expected
> results:
>
> Scene.objects.filter(name__contains='ME').using('scenes')
> [, ]
>
> If I perform a get(), Django seems to get completely confused and
> tries to read the data from the default database:
>
>
> Scene.objects.get(id=3).using('scenes')
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "/usr/lib/python2.6/site-packages/django/db/models/manager.py",
> line 132, in get
>    return self.get_query_set().get(*args, **kwargs)
>  File "/usr/lib/python2.6/site-packages/django/db/models/query.py",
> line 341, in get
>    % self.model._meta.object_name)
> DoesNotExist: Scene matching query does not exist.
>
> Anyone else seen this?

Django isn't getting confused; it's doing exactly what you have asked for.

The problem is caused by the fact that get() doesn't return a queryset
-- it returns a single object. If, for some reason, there *was* a
matching scene in the default database, the next error you would see
would be "Scene object has no method 'using()'". You can't apply *any*
queryset operation to the end of a get(); get() is a terminal clause
on a queryset.

get() behaves differently to filter() because filter() returns a
queryset, not a single object. As a result, you can apply using() to a
filtered queryset to yield a new queryset directed at a different
database. Querysets are lazily evaluated, so it doesn't matter when
you put the using() call in the query, as long as has been added when
you iterate over the final results.

Yours,
Russ Magee %-)

-- 
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: Import csv file in admin

2010-10-27 Thread Jorge

On Oct 27, 7:43 pm, Jorge  wrote:
> > On 27/10/2010, Daniel Roseman  wrote:
>
> > > You're setting the values on `self` in the form's save method. In
> > > other words, you're setting them on the *form*, not the instance. You
> > > should be setting them on `form_instance`.
>
> > > Also, don't convert the decimals to float. Decimal accepts a string
> > > value, and converting to float will just introduce possible floating-
> > > point precision errors.
> > > --
> > > DR.
>
> Thanks Daniel!
>
> I do some changes:
>
> Forms.py:
>
> def save(self, commit=True, *args, **kwargs):
>         form_input = super(DataInput, self).save(commit=False, *args,
> **kwargs)
>         form_input.place = self.cleaned_data['place']
>         form_input.file = self.cleaned_data['file']
>         records = csv.reader(form_input.file)
>         for line in records:
>             self.time = datetime.strptime(line[1], "%m/%d/%y %H:%M:
> %S")
>             self.data_1 = line[2]
>             self.data_2 = line[3]
>             self.data_3 = line[4]
>             form_input.save()
>
> But i'm still get the same IntegrityError. The csv file is fine, so i
> don't know why is null.
>
> Regards!

Shame on me!
I forgot to make some changes inside the for loop.
So now it is:

 def save(self, commit=True, *args, **kwargs):
 form_input = super(DataInput, self).save(commit=False, *args,
 **kwargs)
 form_input.place = self.cleaned_data['place']
 form_input.file = self.cleaned_data['file']
 records = csv.reader(form_input.file)
 for line in records:
 form_input.time = datetime.strptime(line[1], "%m/%d/%y %H:
%M:
 %S")
 form_input.data_1 = line[2]
 form_input.data_2 = line[3]
 form_input.data_3 = line[4]
 form_input.save()

But, i've got a new error message! an attribute error: 'NoneType'
object has no attribute 'save'.
What can it be?

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



Model Inheritance.

2010-10-27 Thread Tom Eastman
I'm working with model inheritance, and I need to convert my objects 
into instances of its subclass.  Is there an easy way to do this?



Looking at the example in:


http://docs.djangoproject.com/en/1.2/topics/db/models/#multi-table-inheritance


I have a whole bunch of 'Place' objects that are in my database, and I 
want to turn them into 'Restaurant' objects.  How can I achieve this?


(I want to end up with the implicit one-to-one relation in 'Restaurant' 
to be pointing to the already existing object in 'Place')


Cheers!

Tom

--
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: Import csv file in admin

2010-10-27 Thread Jorge


On Oct 27, 1:58 pm, Jirka Vejrazka  wrote:
> If you don't mind me asking, why do use ModelForm and not the ORM
> directly? I'm just curious as using just a model (possibly wirh model
> validation) seems like easies approach.
>
>   Cheers
>
>     Jirka

Hi Jirka!

The idea behind the modelform is bring an intuitive way to the admin
of the site (a non django-developer) for doing the import of several
files. If with the ORM i can do something similar, it will be great!
There's something i can read to get into it?

> On 27/10/2010, Daniel Roseman  wrote:
>
>
> > You're setting the values on `self` in the form's save method. In
> > other words, you're setting them on the *form*, not the instance. You
> > should be setting them on `form_instance`.
>
> > Also, don't convert the decimals to float. Decimal accepts a string
> > value, and converting to float will just introduce possible floating-
> > point precision errors.
> > --
> > DR.
>

Thanks Daniel!

I do some changes:

Forms.py:

def save(self, commit=True, *args, **kwargs):
form_input = super(DataInput, self).save(commit=False, *args,
**kwargs)
form_input.place = self.cleaned_data['place']
form_input.file = self.cleaned_data['file']
records = csv.reader(form_input.file)
for line in records:
self.time = datetime.strptime(line[1], "%m/%d/%y %H:%M:
%S")
self.data_1 = line[2]
self.data_2 = line[3]
self.data_3 = line[4]
form_input.save()

But i'm still get the same IntegrityError. The csv file is fine, so i
don't know why is null.

Regards!

-- 
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: Displaying (only) custom form fields in a template.

2010-10-27 Thread ShawnMilo
I found a solution, but it's kind of ugly. In the form I added this:

self.fields[field_name].is_custom = True

And in the model:

{% for field in form %}
{% if field.field.is_custom %}
{{ field.label }} {{ field }}
{% endif %}
{% endfor %}

Is there a clean way to do this?

Thanks,
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-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: overriding save-method

2010-10-27 Thread Patrick
hm .. i thought of that too but i considered it not to be the best
approach.
i will try that snippet though.. thank you!

On 27 Okt., 15:49, Shawn Milochik  wrote:
> Try this instead:
>
> http://djangosnippets.org/snippets/1478/
>
> Or you could do it manually in your model:
>
> 1. Add field _value_json to your model.
> 2. Add functions (get_value, set_value) which do the simplejson work.
> 3. Add a property named 'value' with get_value and set_value as its
> getter and setter.

-- 
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: help with model definition

2010-10-27 Thread pixelcowboy
The second solution would be great, but is the relationship inherited?
I didnt think that was possible. Will try it out, first solution is
also an option. Thanks for your help.

On Oct 27, 1:35 pm, Marc Aymerich  wrote:
> On Tue, Oct 26, 2010 at 6:21 PM, pixelcowboy wrote:
>
> > I have a question regarding the best way to conceptualize a model. I
> > have a tasks model, which I want to hook to a few different other
> > models: The model Project, the model Company and a few other undefined
> > models. The problem is that I want a particular instance of the task
> > to be pluggable to one and only one of those models, which I dont know
> > how I would achieve using 2 or more separate foreign keys. The only
> > idea I have is to use generic relationships, and unique them. Any
> > ideas?
>
> Maybe something like this?
>
> class Base(models.Model):
>     pass
>
> class Project(Base):
>     pass
>
> class Company(Base):
>     pass
>
> class Task(models.Model):
>      base = models.ForeignKey(Base)
>
> --
> Marc

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



Displaying (only) custom form fields in a template.

2010-10-27 Thread Shawn Milochik
I'm using Django 1.1.

I have a forms.Form that has fields in it, and I'm dynamically
creating custom fields, each with a name beginning with 'custom_.'

In my template I'm already displaying the non-custom fields. I need to
be able to show just the custom fields.

How do I iterate through only the custom fields in my template?

What I've tried:

Adding a copy() of self.fields named custom_fields in the form so
I could iterate through custom_fields in the template, but the fields
will not display.

Saved the names of the custom fields in a list, and in the
template tried iterating though those like so:

{% for fieldname in form.custom_field_names %}

{{ additional_content.form.fieldname }}
{# this doesn't work #}
{{ additional_content.form.fields.fieldname }}{# 
neither does this #}

{% endfor %}

 I'm assuming some special handling of the fields is happening during
template rendering which thwarts my attempted workarounds.

Thanks,
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-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: Factory Squirrel

2010-10-27 Thread Łukasz Rekucki
On 27 October 2010 22:17, Phlip  wrote:
> Djangoes:
>
> RoR has a fixture system called Factory Girl, which I suspect
> constructs objects in native Ruby, not in JSON/YAML.
>
> If nobody ports it to Django I would; under the name "Factory
> Squirrel".

http://github.com/dnerdy/factory_boy

Also, there is a more general python solution:
http://farmdev.com/projects/fixture/ that supports django. You should
probably check it out for inspiration before writing a one from
scratch.

-- 
Łukasz Rekucki

-- 
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: help with model definition

2010-10-27 Thread Marc Aymerich
On Tue, Oct 26, 2010 at 6:21 PM, pixelcowboy wrote:

> I have a question regarding the best way to conceptualize a model. I
> have a tasks model, which I want to hook to a few different other
> models: The model Project, the model Company and a few other undefined
> models. The problem is that I want a particular instance of the task
> to be pluggable to one and only one of those models, which I dont know
> how I would achieve using 2 or more separate foreign keys. The only
> idea I have is to use generic relationships, and unique them. Any
> ideas?


Maybe something like this?

class Base(models.Model):
pass

class Project(Base):
pass

class Company(Base):
pass

class Task(models.Model):
 base = models.ForeignKey(Base)

-- 
Marc

-- 
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: What does an ideal django workflow setup look like?

2010-10-27 Thread Ken
Ok -

I put together more research. It's a huge pile of links. Hope this
helps as additional places to learn/look. As a disclaimer, I'm a noob,
which is why I am providing Internet research instead of a personal
expert opinion.

--Simon Willison (co-Founder of Django) answered the question at
Quora.com--

Short answer: virtualenv, pip, south for migrations, fabric for
deployment.

Long answer: I haven't seen the perfect tutorial covering all of the
above yet, which is a shame, but here are some good links:

http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p.html

http://www.saltycrane.com/blog/2009/05/notes-using-pip-and-virtualenv-django/

http://www.clemesha.org/blog/modern-python-hacker-tools-virtualenv-fabric-pip

http://www.caktusgroup.com/blog/2010/04/22/basic-django-deployment-with-virtualenv-fabric-pip-and-rsync/

---Hacker News threads

http://news.ycombinator.com/item?id=1824171

http://news.ycombinator.com/item?id=1827160

http://news.ycombinator.com/item?id=135829

The next few are more git-focused.

http://news.ycombinator.com/item?id=1343753

http://news.ycombinator.com/item?id=441670

--Old Reddit threads

http://www.reddit.com/r/django/comments/dpnfr/fabric_django_git_apache_mod_wsgi_virtualenv_and/

http://www.reddit.com/r/django/comments/95oeo/django_development_workflow/

http://www.reddit.com/r/programming/comments/a5j8b/mozilla_addons_team_switching_to_django_git_and/

On Oct 26, 8:26 am, Celso González  wrote:
> On Fri, Oct 22, 2010 at 08:02:56AM -0700, Ken wrote:
>
> Hi
>
> > I understand there are many different ways and products to use to
> > setup a great workflow for developing in django, but would like to
> > hear how you or your startup team (or corporate dev group) does it.
> > Specifics would be amazing, as I need a little hand holding, i.e.
> > please cover anything and everything that I should know in order to
> > develop efficiently, robustly, and eventually collaboratively.
>
> There are common ideas like +1 South, local_settings.py, vcs and
> helper scripts like fabric
>
> > Basically, please explain it in a way that a layman can follow the
> > steps and setup a workflow without pulling his hair out. =P
>
> ok, my system
>
> Every project has its own virtual enviroment
>
> -virtualenv
> --bin
> --include
> --lib
> --requirements.txt
> --myproject
> ---apps
> ...
> ---static
> ---templates
>
> *All the structure and contents goes into git or vcs of choice
> *pip freeze > requirements.txt and pip install -r requirements.txt
> to handle the external soft installed
> *in .gitignore I override bin, include, lib, src directories
>
> Just using git and virtualenv im able to create the same enviroment
> quickly in several machines (dev, testing, production)
>
> Still working on the database exports
>
> --
> Celso Gonz lez (PerroVerd)http://mitago.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-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.



Factory Squirrel

2010-10-27 Thread Phlip
Djangoes:

RoR has a fixture system called Factory Girl, which I suspect
constructs objects in native Ruby, not in JSON/YAML.

If nobody ports it to Django I would; under the name "Factory
Squirrel". This post is about the first method I'd add to such a
module.

Another kewt RoR fixture feature is the accessor. Given a table Order
and orders.yml, you can write order(:able) to fetch that Order record
from the sample database.

I miss that feature, so I wrote one better in Django:

class FactorySquirrel:

def __getattr__(self, attr):
sought = re.search(r'^(.*)_([^_]+$)', attr)

if sought:
record_name, model_name = sought.groups()
model = None
try:
model = eval(model_name.capitalize())
except NameError: pass
if model:
record = model.objects.get(name=attr)
setattr(self, attr, record)  #  So we needn't do it
again.
return record
raise AttributeError("%r object has no attribute %r" %
 (type(self).__name__, attr))

Here's how it works. Suppose you have tables Order and User, and they
have 'name' fields with 'kozmik' and 'bullfrog', respectively.

In your test, to fetch a record, you just name it:

   def test_kozmik_bullfrog(self):
   print self.kozmik_order  #  reads the fixture database here
   print self.bullfrog_user
   print self.kozmik_order  #  does not re-read the record

>From here, to be more useful, we need to think of details like records
without names (shameful!). Models with CamelCase already work -
kozmik_LineItem.

Any ideas how to improve this towards a true Squirrel?

--
  Phlip
  http://zeekland.zeroplayer.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-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: help with model definition

2010-10-27 Thread urukay
well, u can add multiple FK relations to your model e.g.:

company = models.ForeignKey(Company, blank=True, null=True)
other_model = models.ForeignKey(OtherModel, blank=True, null=True)

And then in form you just define clean method which will ensure that
one and only one FK relation will be created. And as for admin
interface, just override clean method and save function (not
necessary, clean will prevent to save if it fails).

Or maybe it's possible to define it in Meta class of your model (don't
know, never tried it)

Radovan


On 26. Okt, 18:21 h., pixelcowboy  wrote:
> I have a question regarding the best way to conceptualize a model. I
> have a tasks model, which I want to hook to a few different other
> models: The model Project, the model Company and a few other undefined
> models. The problem is that I want a particular instance of the task
> to be pluggable to one and only one of those models, which I dont know
> how I would achieve using 2 or more separate foreign keys. The only
> idea I have is to use generic relationships, and unique them. Any
> ideas?

-- 
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: How can you change the color of the form's error messages

2010-10-27 Thread Shawn Milochik
The errors are given a standard 'error' class. You can just add CSS to
modify it to your tastes.


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-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 can you change the color of the form's error messages

2010-10-27 Thread Akn
Hi all,
How can I customize the error message that comes from a form from
(e.g. change the color)

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-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 form show initial prepopulate on edit

2010-10-27 Thread Hudar
Hi,

Just wondering, how we could show initial value on the edit form. Let
say we have code like this to retrive the data ;

if request.method == 'GET':
post = models.Post.get_by_key_name(key_name)
editPostForm = postform.PostForm(initial={
  'title': post.title,
  'body': post.body,
  'category': post.category,
  'tags': ' '.join(post.tags)})

return render_to_response('admin/newpost.html', {
 'postForm':editPostForm,
 'action':post.get_edit_url(),})

but when i code the form like this :



it doesnt show up the initial category in the textfield. Please help,
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-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: problems using apps in main project (NameErrors)

2010-10-27 Thread Piotr Zalewa
just add before code:
import site
:)

On 10/27/10 15:13, wawa wawawa wrote:
> Hi Piotr,
> 
> On 27 October 2010 15:54, Piotr Zalewa  wrote:
>> If you want to have the apps in apps folder you need to put them on the
>> python path, so eithor modify the python path environment variable or
>> (prefered) modify manage.py and add
>> site.addsitedir(path('apps'))
> 
> Many thanks for the response.
> 
> A question: I presume this only matters for the dev server then?
> 
> I added this just before "execute_manager(settings)"
> 
> $ python manage.py runserver
> Traceback (most recent call last):
>   File "manage.py", line 11, in 
> site.addsitedir(path('apps'))
> NameError: name 'site' is not defined
> 
> Apologies if I'm being very stupid!
> 
> Thanks
> 
> W
> 
> 
>> zalun
>>
>> On 10/27/10 14:50, wawa wawawa wrote:
>>> Hi All,
>>>
>>> I've spent the last hour or so looking for a clear and simple
>>> explanation to this but I've been unsuccessful. Maybe someone here could
>>> help me (please!)
>>>
>>> What do I need to do to make sure my created apps are useable?
>>>
>>> This is the structure of my "XMLmunger" project.
>>>
>>> In order to simplify my project I want to use different apps for the
>>> major functional bits of the project. First stop is the "upload"
>>> application.
>>> I cannot figure out why my upload app is not being recognised by django.
>>> Note, at the moment I'm only using views / urls and templates. No models
>>> at all.
>>>
>>> 
>>> ├── apps
>>> │   ├── __init__.py (empty)
>>> │   └── upload
>>> │   ├── __init__.py (empty)
>>> │   ├── urls.py
>>> │   └── views.py
>>> ├── __init__.py (empty)
>>> ├── manage.py
>>> ├── public
>>> │   └── static (css, js and images)
>>> ├── settings.py
>>> ├── templates
>>> │   └── (all of my templates)
>>> ├── urls.py
>>> └── views.py
>>>
>>>  - In my /settings.py I added "upload" to "INSTALLED_APPS".
>>>  - In my apps directory I have __init__.py (empty) to allow all sub dirs
>>> to be imported as modules.
>>>  - I would like to pass all urls for an app to the urls.py in that app
>>> directory:  (r"^/upload$", include('upload.urls'))
>>>
>>> Now the dev server won't start, complaining:
>>>
 python manage.py runserver
>>> Error: No module named upload
>>>
>>> OK. Let's change "upload" to "apps.upload" in INSTALLED_APPS.
>>>
>>> Now the dev server starts but any page I try to go to gives: NameError
>>> at / "name 'apps' is not defined".
>>>
>>> I have a feeling I'm missing something very obvious but everything
>>> djangoesque is still forming in my mind and I'm really not sure where
>>> the problem is.
>>>
>>> I've been trying "from XMLMunger.view import *" in my root urls.py
>>> without success. I am thinking that I do need to import but I'm just not
>>> sure where and what...
>>>
>>> Thanks in advance...
>>>
>>> W
>>>
>>> --
>>> 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.
>>
>>
>> --
>> blog  http://piotr.zalewa.info
>> jobs  http://webdev.zalewa.info
>> twit  http://twitter.com/zalun
>> face  http://facebook.com/zaloon
>>
>> --
>> 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.
>>
>>
> 


-- 
blog  http://piotr.zalewa.info
jobs  http://webdev.zalewa.info
twit  http://twitter.com/zalun
face  http://facebook.com/zaloon

-- 
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: problems using apps in main project (NameErrors)

2010-10-27 Thread wawa wawawa
Hi Piotr,

On 27 October 2010 15:54, Piotr Zalewa  wrote:
> If you want to have the apps in apps folder you need to put them on the
> python path, so eithor modify the python path environment variable or
> (prefered) modify manage.py and add
> site.addsitedir(path('apps'))

Many thanks for the response.

A question: I presume this only matters for the dev server then?

I added this just before "execute_manager(settings)"

$ python manage.py runserver
Traceback (most recent call last):
  File "manage.py", line 11, in 
site.addsitedir(path('apps'))
NameError: name 'site' is not defined

Apologies if I'm being very stupid!

Thanks

W


> zalun
>
> On 10/27/10 14:50, wawa wawawa wrote:
>> Hi All,
>>
>> I've spent the last hour or so looking for a clear and simple
>> explanation to this but I've been unsuccessful. Maybe someone here could
>> help me (please!)
>>
>> What do I need to do to make sure my created apps are useable?
>>
>> This is the structure of my "XMLmunger" project.
>>
>> In order to simplify my project I want to use different apps for the
>> major functional bits of the project. First stop is the "upload"
>> application.
>> I cannot figure out why my upload app is not being recognised by django.
>> Note, at the moment I'm only using views / urls and templates. No models
>> at all.
>>
>> 
>> ├── apps
>> │   ├── __init__.py (empty)
>> │   └── upload
>> │       ├── __init__.py (empty)
>> │       ├── urls.py
>> │       └── views.py
>> ├── __init__.py (empty)
>> ├── manage.py
>> ├── public
>> │   └── static (css, js and images)
>> ├── settings.py
>> ├── templates
>> │   └── (all of my templates)
>> ├── urls.py
>> └── views.py
>>
>>  - In my /settings.py I added "upload" to "INSTALLED_APPS".
>>  - In my apps directory I have __init__.py (empty) to allow all sub dirs
>> to be imported as modules.
>>  - I would like to pass all urls for an app to the urls.py in that app
>> directory:  (r"^/upload$", include('upload.urls'))
>>
>> Now the dev server won't start, complaining:
>>
>>>python manage.py runserver
>> Error: No module named upload
>>
>> OK. Let's change "upload" to "apps.upload" in INSTALLED_APPS.
>>
>> Now the dev server starts but any page I try to go to gives: NameError
>> at / "name 'apps' is not defined".
>>
>> I have a feeling I'm missing something very obvious but everything
>> djangoesque is still forming in my mind and I'm really not sure where
>> the problem is.
>>
>> I've been trying "from XMLMunger.view import *" in my root urls.py
>> without success. I am thinking that I do need to import but I'm just not
>> sure where and what...
>>
>> Thanks in advance...
>>
>> W
>>
>> --
>> 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.
>
>
> --
> blog  http://piotr.zalewa.info
> jobs  http://webdev.zalewa.info
> twit  http://twitter.com/zalun
> face  http://facebook.com/zaloon
>
> --
> 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.
>
>

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



Problems limiting get_next_by_FOO inside a django view?

2010-10-27 Thread tricks
have used get_next_by_FOO inside my view to display an absolute url
for the following item within a set of records however when it gets to
the end of the query set an error is raised.

how do I stop my view from raising this error and instead just
outputting some html letting me know that it has come to the end of
the set?

All help is greatly appreciated.

def news_view(request, url):
news = get_object_or_404(Body, url=url)
next = news.get_next_by_published()
pre = news.get_previous_by_published()
return render_to_response('news/news_view.html', {
'news': news,
'pre': pre,
'next': next
}, context_instance=RequestContext(request)


current template
Next News
Previous News

-- 
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: Override DECIMAL_SEPARATOR in certain cases?

2010-10-27 Thread Joachim Pileborg
Seems weird that no one have had this problem before... Maybe no one
is using any other locale than en-us?

Anyway, I solved it by making a custom template filter called
"dotify", which if it gets a floating point number, converts it to a
string, and replaces all commas with "dots":

def dotify(value):
if isinstance(value, basestring):
return string.replace(',', '.')
elif isinstance(value, float):
return ('%f' % value).replace(',', '.')
else:
return value
dotify = register.filter(dotify)

/ Joachim

-- 
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: How do you create a view that returns the next object in a given list?

2010-10-27 Thread tricks
get_next_by_FOO

http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_next_by_FOO

-- 
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: How do you create a view that returns the next object in a given list?

2010-10-27 Thread tricks
get_next_by_FOO

http://docs.djangoproject.com/en/dev/ref/models/instances/#django.db.models.Model.get_next_by_FOO

-- 
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: problems using apps in main project (NameErrors)

2010-10-27 Thread Piotr Zalewa
Hi

If you want to have the apps in apps folder you need to put them on the
python path, so eithor modify the python path environment variable or
(prefered) modify manage.py and add
site.addsitedir(path('apps'))

zalun

On 10/27/10 14:50, wawa wawawa wrote:
> Hi All,
> 
> I've spent the last hour or so looking for a clear and simple
> explanation to this but I've been unsuccessful. Maybe someone here could
> help me (please!)
> 
> What do I need to do to make sure my created apps are useable?
> 
> This is the structure of my "XMLmunger" project.
> 
> In order to simplify my project I want to use different apps for the
> major functional bits of the project. First stop is the "upload"
> application.
> I cannot figure out why my upload app is not being recognised by django.
> Note, at the moment I'm only using views / urls and templates. No models
> at all.
>  
> 
> ├── apps
> │   ├── __init__.py (empty)
> │   └── upload
> │   ├── __init__.py (empty)
> │   ├── urls.py
> │   └── views.py
> ├── __init__.py (empty)
> ├── manage.py
> ├── public
> │   └── static (css, js and images)
> ├── settings.py
> ├── templates
> │   └── (all of my templates)
> ├── urls.py
> └── views.py
> 
>  - In my /settings.py I added "upload" to "INSTALLED_APPS".
>  - In my apps directory I have __init__.py (empty) to allow all sub dirs
> to be imported as modules.
>  - I would like to pass all urls for an app to the urls.py in that app
> directory:  (r"^/upload$", include('upload.urls'))
> 
> Now the dev server won't start, complaining:
> 
>>python manage.py runserver 
> Error: No module named upload
> 
> OK. Let's change "upload" to "apps.upload" in INSTALLED_APPS.
> 
> Now the dev server starts but any page I try to go to gives: NameError
> at / "name 'apps' is not defined".
> 
> I have a feeling I'm missing something very obvious but everything
> djangoesque is still forming in my mind and I'm really not sure where
> the problem is.
> 
> I've been trying "from XMLMunger.view import *" in my root urls.py
> without success. I am thinking that I do need to import but I'm just not
> sure where and what...
> 
> Thanks in advance...
> 
> W
> 
> -- 
> 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.


-- 
blog  http://piotr.zalewa.info
jobs  http://webdev.zalewa.info
twit  http://twitter.com/zalun
face  http://facebook.com/zaloon

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



problems using apps in main project (NameErrors)

2010-10-27 Thread wawa wawawa
Hi All,

I've spent the last hour or so looking for a clear and simple explanation to
this but I've been unsuccessful. Maybe someone here could help me (please!)

What do I need to do to make sure my created apps are useable?

This is the structure of my "XMLmunger" project.

In order to simplify my project I want to use different apps for the major
functional bits of the project. First stop is the "upload" application.
I cannot figure out why my upload app is not being recognised by django.
Note, at the moment I'm only using views / urls and templates. No models at
all.


├── apps
│   ├── __init__.py (empty)
│   └── upload
│   ├── __init__.py (empty)
│   ├── urls.py
│   └── views.py
├── __init__.py (empty)
├── manage.py
├── public
│   └── static (css, js and images)
├── settings.py
├── templates
│   └── (all of my templates)
├── urls.py
└── views.py

 - In my /settings.py I added "upload" to "INSTALLED_APPS".
 - In my apps directory I have __init__.py (empty) to allow all sub dirs to
be imported as modules.
 - I would like to pass all urls for an app to the urls.py in that app
directory:  (r"^/upload$", include('upload.urls'))

Now the dev server won't start, complaining:

>python manage.py runserver
Error: No module named upload

OK. Let's change "upload" to "apps.upload" in INSTALLED_APPS.

Now the dev server starts but any page I try to go to gives: NameError at /
"name 'apps' is not defined".

I have a feeling I'm missing something very obvious but everything
djangoesque is still forming in my mind and I'm really not sure where the
problem is.

I've been trying "from XMLMunger.view import *" in my root urls.py without
success. I am thinking that I do need to import but I'm just not sure where
and what...

Thanks in advance...

W

-- 
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: overriding save-method

2010-10-27 Thread Shawn Milochik
Try this instead:

http://djangosnippets.org/snippets/1478/

Or you could do it manually in your model:

1. Add field _value_json to your model.
2. Add functions (get_value, set_value) which do the simplejson work.
3. Add a property named 'value' with get_value and set_value as its
getter and setter.

-- 
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: Django job needed

2010-10-27 Thread roberto
http://code.djangoproject.com/wiki/DjangoJobs
http://djangozen.com/jobs/
http://www.python.org/community/jobs/

Good luck !

On Oct 26, 10:41 pm, Venkatraman S  wrote:
> On Wed, Oct 27, 2010 at 1:04 AM, Swordfish  wrote:
> > Hi everybody! I'm looking for a job deals with Django.
> > Interesting in any kind of work: filling websites with images, texts,
> > translations, testing.
> > I'am Django newbie.Have previous experience with Plone.
>
> http://djangogigs.com/
>
> All the Best.
>
> -V

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



overriding save-method

2010-10-27 Thread Patrick
hi,

i am trying to override the save-method of one of my models. i want to
save the json-representation of any object in a text field. somehow it
doesn't seem to work.

class Setting(models.Model):
name = models.CharField(max_length=100)
value = models.TextField()

def save(self, *args, **kwargs):
self.value = json.dumps(self.value)
super(Setting, self).save(*args, **kwargs)

any ideas?! thank you..

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



Open Source Developer Network for Django Developers

2010-10-27 Thread Sandra
We release an innovative social network and collaboration platform
with capabilities to develop your Django project alone or together
with like-minded developers, e.g. code hosting with 2 GB free disk
space. The project is open source and free-of-charge. Take a look
under http://bettercodes.org

Regards,
Sandra

-- 
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: change the default widget to a field in a modelform

2010-10-27 Thread refreegrata
If somebody know some way to save a Manytomany field (the
departments)  manually in the view and not with form.save() would be
helpful.

-- 
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: change the default widget to a field in a modelform

2010-10-27 Thread refreegrata
Yes, I know that, this is strange. My models.
--
Table 1: Enterprise
Table 2: Department with : fk_enterprise =
models.ForeignKey(Enterprise)
Table 3: Item with: fk_departament =
models.ManyToManyField(Departament) 

Re: Database Setup

2010-10-27 Thread Sithembewena Lloyd Dube
Thanks Everett!

On Sat, Oct 23, 2010 at 4:24 AM, Everett  wrote:

> Thanks everyone for all your help! I found a binary for Python 2.7
> Here's a the link: http://www.codegood.com/archives/129
> Just in case someone stumbles upon these posts.
>
> On Oct 16, 3:58 pm, Karen Tracey  wrote:
> > 2010/10/16 Jonathan Barratt 
> >
> > > Hope you have visual studio installed! :p
> >
> > If you do not, or if you do not want to go to the trouble of building
> > MySQLdb from source, it is usually possible to find Windows binary
> packages
> > for MySQLdb by searching Google with terms like:
> >
> > mysqldb windows binaries python 2.7
> >
> > I have never built MySQLdb from scratch on Windows, I've always used
> > pre-built binaries. (Though I have also not yet bothered to find binaries
> > for Python 2.7...I have Windows boxes and use them for testing Django but
> I
> > do not actually do any Django development on them, and I have not had
> time
> > lately to do much Windows testing.)
> >
> > Karen
>
> --
> 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.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.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-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 do you create a view that returns the next object in a given list?

2010-10-27 Thread tricks...@googlemail.com
I have a view that displays object information when the correct URL is
provided however I would like to create a similar view that returns
url information from the record that is located next.

So in essence take the info from my first view, list/order it in some
way preferably by date and return the records located next and
previous in the list.

Can somebody please explain to me and provide a simple example of how
I would do this. I am new to django and I am stuck. All Help is
greatly appreciated. Thanks.

Here are the models URLs and views I have used

Model

class Body(models.Model):
type = models.ForeignKey(Content)
url = models.SlugField(unique=True, help_text='A Google friendly
title.')
published = models.DateTimeField(default=datetime.now)
maintxt = models.CharField(max_length=200)

View

def news_view(request, url):
news = get_object_or_404(Body, url=url)
return render_to_response('news/news_view.html', {
'news': news
}, context_instance=RequestContext(request))

URL

url(r'^/(?P[\w\-]+)/$', 'news_view', name="news_view"),

-- 
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: Problem with Mysql Quires in django

2010-10-27 Thread Daniel Roseman
On Oct 27, 10:19 am, Jagdeep Singh Malhi 
wrote:
> hi
> I want to use this mysql Query
> " SELECT count(*) as class_roll_no FROM student_profile where
> class_roll_no !='00 '  ";
> in my  view file
>
> Is it possible?
>
> I try this code
> view.py file is :
>
> from django.shortcuts import render_to_response
> from mysite.student.models import Profile
> from django.db.models import Count
>
> def fulldetail(request):
>     fulldetail = Profile.objects.all().order_by('class_roll_no')
>     total_count = Profile.objects.filter( class_roll_no !='00')
>     total = total_count.count()
>     return render_to_response("userprofile/profile/fulldetail.html",
> {"fulldetail" : fulldetail, "total":total} )
>
> Is this correct way to use this?
> if not please help or give any tutorials how to use mysql quires with
> some conditions.

http://docs.djangoproject.com/en/1.2/topics/db/queries/

BTW this question has nothing to do with MySQL.
--
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-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: How to display image in django template

2010-10-27 Thread girish shabadimath
Another way for static images:
Its good to have all html related stuffs (html files, images, ..etc) in one
directory (ex: html directory)

In settings.py there is a field called TEMPLATE_DIR, add the absolute-path
to the html directory to this filed
ex: TEMPLATE_DIR = 'path-to-html-directory',

in template, access the image as 


On Mon, Oct 25, 2010 at 4:12 PM, Kenneth Gonsalves wrote:

> On Mon, 2010-10-25 at 03:34 -0700, d wrote:
> > I have been searching for solutions whole day.
> > How would I display image file in django template. I have already set
> > MEDIA_ROOT and MEDIA_URL.
>
> assume a model:
>
> Mymodel(models.Model):
> photo = models.ImageField("somename",upload_to="images/")
>
> get an instance:
>
> myob = Mymodel.objects.get(pk=1)
>
> in your template:
>
> 
> --
> regards
> Kenneth Gonsalves
> Senior Associate
> NRC-FOSS at AU-KBC
>
> --
> 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.
>
>


-- 
Girish M S

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



Problem with Mysql Quires in django

2010-10-27 Thread Jagdeep Singh Malhi
hi
I want to use this mysql Query
" SELECT count(*) as class_roll_no FROM student_profile where
class_roll_no !='00 '  ";
in my  view file

Is it possible?

I try this code
view.py file is :

from django.shortcuts import render_to_response
from mysite.student.models import Profile
from django.db.models import Count

def fulldetail(request):
fulldetail = Profile.objects.all().order_by('class_roll_no')
total_count = Profile.objects.filter( class_roll_no !='00')
total = total_count.count()
return render_to_response("userprofile/profile/fulldetail.html",
{"fulldetail" : fulldetail, "total":total} )

Is this correct way to use this?
if not please help or give any tutorials how to use mysql quires with
some conditions.

template file code is:

Total  = {{ total }}

PHOTONAMEROLL NOBRANCH

{% if fulldetail %}
{% for part in fulldetail %}
   {% if part.firstname %}
{% if part.photo %} {% endif %}{{ part.firstname }}
{{ part.middlename }} {{ part.lastname }}{{ part.class_roll_no}} {{ part.branch }}
  {% endif %}
{% endfor %}
{% else %}
 Data is Not available.
{% endif %}



I only count number of entry with condition.

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-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: interface django and rest

2010-10-27 Thread sami nathan
But is telling about piston is i am very beginner of django i want to
inerface django and RESTFULL service and i am also blinking with what
to do with my wsdl file Please help by 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-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: interface django and rest

2010-10-27 Thread Jirka Vejrazka
> Please Suggest me an tutorial for interfacing django and  restfuli thanks

 Hi Sami,

  you might want to check this out:
http://bitbucket.org/jespern/django-piston/wiki/Home

   Jirka

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



interface django and rest

2010-10-27 Thread sami nathan
Please Suggest me an tutorial for interfacing django and  restfuli 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-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: Import csv file in admin

2010-10-27 Thread Daniel Roseman
On Oct 27, 4:27 am, Jorge  wrote:
> I'm trying to poblate a database with a csv file using the modelform
> in Admin site. Here's the files:
>
> Models.py:
>
> class Data(models.Model):
>         place = models.ForeignKey(Places)
>         time = models.DateTimeField(blank=True)
>         data_1 = models.DecimalField(max_digits=3, decimal_places=1,
> blank=True)
>         data_2 = models.DecimalField(max_digits=3, decimal_places=1,
> blank=True)
>         data_3 = models.DecimalField(max_digits=4, decimal_places=1,
> blank=True)
>
> Forms.py:
>
> import csv
> from datetime import datetime
>
> class DataInput(ModelForm):
>     file = forms.FileField()
>
>     class Meta:
>         model = Data
>         fields = ("file", "place")
>
>     def save(self, commit=True, *args, **kwargs):
>         form_input = super(DataInput, self).save(commit=False, *args,
> **kwargs)
>         self.place = self.cleaned_data['place']
>         self.file = self.cleaned_data['file']
>         records = csv.reader(self.file)
>         for line in records:
>             self.time = datetime.strptime(line[1], "%m/%d/%y %H:%M:
> %S")
>             self.data_1 = float(line[2])
>             self.data_2 = float(line[3])
>             self.data_3 = float(line[4])
>             form_input.save()
>
> test.csv (it's only one line for test purposes, the real file has much
> more lines):
> 1,5/18/10 11:45:00,1.2,2.7,205.
>
> When i put the file got an IntegrityError: datas_data.time may not be
> NULL ; and the problem is in Forms.py line: form_input.save()
>
> What i'm missing?!

You're setting the values on `self` in the form's save method. In
other words, you're setting them on the *form*, not the instance. You
should be setting them on `form_instance`.

Also, don't convert the decimals to float. Decimal accepts a string
value, and converting to float will just introduce possible floating-
point precision errors.
--
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-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: for loop logic in template

2010-10-27 Thread Daniel Roseman
On Oct 27, 5:33 am, jimgardener  wrote:
> hi
> I have a model with 3 fields
> class Employee(models.Model):
>     name=models.CharField(max_length=50)
>     home_address=models.TextField(blank=True)
>     change_filter=models.IntegerField()
>
> I am creating a modelform using this class as model.
> class EmployeeForm(ModelForm):
>     class Meta:
>         model=Employee
>
> In my template,I want to give the IntegerField some special
> treatment ..ie,I want to render it as input type="range" instead of a
> text field.
> I can do this like,
> ...
> 
>  Enter name:
>  {{empform.name}}
> 
> 
> {{empform.name.errors}}
> 
> 
>  Enter address:
>  {{empform.home_address}}
> 
> 
> {{empform.home_address.errors}}
> 
>
> 
>  select change filter value:
>          min="0"
>        max="1000"
>        step="2"
>        value="6" id="id_change_filter" name="change_filter"/>
> 
> 
> {{empform.change_filter.errors}}
> 
>
> 
> 
>
> Here ,I am using the same logic for the first two fields..
> I want to render the change_filter using an input type="render"..
> so I thought I can take care of this using a for loop.
> {% for field in empform %}
>     {% ifequal field.name "change_filter" %}
>       
>            select change filter value: label>
>                        min="0"
>            max="1000"
>            step="2"
>            value="6" id="id_change_filter" name="change_filter"/>
>       
>     {% else %}
>     
>     {{ field.label_tag }}: {{ field }}
>     
>     {% endifequal %}
>     {%if  field.errors %}
>         {{field.errors}}
>     {% endif %}
> {% endfor %}
>
> This gives the desired effect..But I am wondering if hardcoding the
> field's name in the ifequal tag is the correct way.Can I check the
> type of field instead?I am not sure how to do this..
> Any advice would be nice..
> thanks
> jim

Don't do this in the template. Define a custom widget for your field,
which outputs the range input. Look at the code for the standard
widgets in django.forms.widgets to see how to do it.
--
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-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: change the default widget to a field in a modelform

2010-10-27 Thread Daniel Roseman
On Oct 26, 7:54 pm, refreegrata  wrote:
> maybe I not explain correctly. For any modelForm the forms for a field
> "ManytoMany"  are "select multiple". If I want to change this I must
> to redefine the widget for that field in the declaration of the
> "modelForm". This works correctly, I can transform the field from
> "select multiple" to any "form" that I want. The problem appear when I
> want to save the "form". Always the "form" is invalid because the
> field type isn't a "select multiple". With a "select multiple" the
> form can be saved, with other field types fail. Somebody have an idea?
> Something that i can do in the view? Any opinion  can be helpful.
>
> Thank for read

I don't understand why you want to use a ManyToMany with a single
select widget. The reason why it doesn't work is that that widget
doesn't make sense for that field - a ManyToMany field has *many*
related values, hence the name. If you think you need a single select,
then it seems your model structure is wrong, and you should be using a
ForeignKey rather than a ManyToManyField.
--
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-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: Editing user profiles via "inlines" breaks password management in admin site

2010-10-27 Thread derek
Actually, it seems more complex...  you now have a 2 stage operation
to carry out what should be a relatively(?) simple operation - add a
user with their details.

I have *exactly* the same problem as the original user - is there no
one else who has managed to create a usuable User+Profile admin edit
form?

(Sidebar: Django is all kinds of wonderful, but user management seems
strangely clunky compared to all the other goodness...)

On Oct 13, 1:48?pm, Martin Burger  wrote:
> Oh, thanks! Actually, it's much simpler this way.
>
> On Oct 13, 12:29?pm, Jonathan Barratt 
> wrote:
>
>
>
> > On 13 ?.?. 2010, at 17:19, Martin Burger wrote:
>
> > > Hello,
>
> > > I implemented a user profile that is activated via AUTH_PROFILE_MODULE
> > > in settings.py. In order to be able to view and edit user profiles in
> > > the admin site, I used the method described at
> > >http://stackoverflow.com/questions/3400641/how-do-i-inline-edit-a-dja
> > > Basically, this method uses a custom ModelAdmin to enable inline
> > > editing.
>
> > > 
> > > How can I enable viewing / editing of user profiles while preserving
> > > the original password functionality?
>
> > The way I'm doing this is just to add 
> > "admin.site.register(models.UserProfile)" to my admin.py
>
> > This makes the user profiles available through the admin section as a 
> > separate entity, like any other model class. It's not in-line editing under 
> > the same section as the basic Django user module, so you do have to create 
> > the user first and then create their profile separately, but it avoids the 
> > problems you're running into and seems like the simplest solution to your 
> > problem to me...
>
> > Others with more Django experience may have a better answer for you though.
>
> > Best wishes,
> > Jonathan

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



Import csv file in admin

2010-10-27 Thread Jorge
I'm trying to poblate a database with a csv file using the modelform
in Admin site. Here's the files:

Models.py:

class Data(models.Model):
place = models.ForeignKey(Places)
time = models.DateTimeField(blank=True)
data_1 = models.DecimalField(max_digits=3, decimal_places=1,
blank=True)
data_2 = models.DecimalField(max_digits=3, decimal_places=1,
blank=True)
data_3 = models.DecimalField(max_digits=4, decimal_places=1,
blank=True)

Forms.py:

import csv
from datetime import datetime

class DataInput(ModelForm):
file = forms.FileField()

class Meta:
model = Data
fields = ("file", "place")

def save(self, commit=True, *args, **kwargs):
form_input = super(DataInput, self).save(commit=False, *args,
**kwargs)
self.place = self.cleaned_data['place']
self.file = self.cleaned_data['file']
records = csv.reader(self.file)
for line in records:
self.time = datetime.strptime(line[1], "%m/%d/%y %H:%M:
%S")
self.data_1 = float(line[2])
self.data_2 = float(line[3])
self.data_3 = float(line[4])
form_input.save()

test.csv (it's only one line for test purposes, the real file has much
more lines):
1,5/18/10 11:45:00,1.2,2.7,205.

When i put the file got an IntegrityError: datas_data.time may not be
NULL ; and the problem is in Forms.py line: form_input.save()

What i'm missing?!

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