Re: Model and Model Manager override-able methods

2009-12-07 Thread Daniel Roseman
On Dec 8, 4:11 am, Waqqas Jabbar  wrote:
> Hi,
>
> Where can i get the list of ALL the methods that a derive class can override
> for Model and Model Manager classes
>
> goto

>From the source code.

It's just Python. You can override what you like.
--
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: Has form.errors been deprecated?

2009-12-07 Thread Daniel Roseman
On Dec 8, 4:23 am, Continuation  wrote:
> I want a way to tell if the form submitted contains errors or not.
>
> There're django snippets that use the field form.errors to test for
> errors (like this one:http://www.djangosnippets.org/snippets/1094/)
>
> And when I looked at my own form.errors, it indeed contains the error
> messages.
>
> However, there's no mention of form.errors at all in the
> documentation. Has it been deprecated? Is it safe to use it?
>
> If not, any alternatives?

No, it hasn't been deprecated at all. It's in the documentation here:
http://docs.djangoproject.com/en/dev/ref/forms/api/#using-forms-to-validate-data

As that section notes, to check if a form is valid use `is_valid()`,
then use `errors` to actually examine the 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.




Has form.errors been deprecated?

2009-12-07 Thread Continuation
I want a way to tell if the form submitted contains errors or not.

There're django snippets that use the field form.errors to test for
errors (like this one: http://www.djangosnippets.org/snippets/1094/ )

And when I looked at my own form.errors, it indeed contains the error
messages.

However, there's no mention of form.errors at all in the
documentation. Has it been deprecated? Is it safe to use it?

If not, any alternatives?

--

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.




Signals request finished from certain view

2009-12-07 Thread Joshua Partogi
Hi all,

Is it possible to detect a django.core.signals.request_finished but
only from a certain view? It seems that I can only get the signal from
every request. I tried to read the documentation but can not find any
reference about this.

Kind regards,

-- 
http://jobs.scrum8.com | http://twitter.com/scrum8

--

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 and Model Manager override-able methods

2009-12-07 Thread Waqqas Jabbar
Hi,

Where can i get the list of ALL the methods that a derive class can override
for Model and Model Manager classes

goto

--

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: Green hosting suggestions for Django?

2009-12-07 Thread Nick Lo
I'm working with 2 clients hosting on and am part leasing servers from Servint 
that I've setup to serve Django applications. Their green initiative is 
outlined here:

http://www.servint.net/servintgreeninitiative.php

Nick

> I'm working on a project for an environmentally-concious client that would 
> like a planet-friendly host, preferably Canadian, though that's not required.
> 
> If that were it, I'd just google "green hosting" and be done with it, but 
> since this is a Django project, I'd really appreciate some 
> recommendations/suggestions from people who have actually deployed a Django 
> site before I sign on.
> 
> Anyone have a story they'd like to share?
> 
> --
> 
> 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.




Queryset filter on foreign key

2009-12-07 Thread GoSantoni
Guys, i'm struggling with this problem for more than a week now. My
goal is to use a queryset filter with a foreign key.
Issues are
1) column generates a list, what is the right way to get the blog id
for a post? So whether the post belongs to blog  1 question or blog 2
answer? Tried  Post.objects.get which fails...
2) howto define this in the template

Any help/ directions are appreciated!

** First I created this model  with a foreign key
**
class blog(models.Model):
function_CHOICES = (
(1, _('question')),
(2, _('answer')),
)
function  = models.IntegerField(_('function'),
choices=function_CHOICES, default=2)

def __unicode__(self):
return self.get_function_display()

class Post(models.Model):
blog = models.ForeignKey(blog)

* This is the view with the 'column definition'
**
def blogs(request, username=None, template_name="blog/blogs.html"):
blogs = Post.objects.filter(status=2).select_related
(depth=1).order_by("-publish")
column = Post.objects.values(blog__id).select_related('blog')

   if column == 1:
 blogs = blogs.filter(author=user).exclude(column==2)

   pass
 blogs = blogs.filter(author=user).exclude(column==1)

   return render_to_response(template_name, {
   "blogs": blogs,
   }, context_instance=RequestContext(request))

* Template. Goal: create 2 columns filtered by whether column
=1 or 2 




{% if blogs %}
{% trans "These are blog posts from everyone:" %}
  {% autopaginate blogs %}

** if column == 1 **
{% for blog_post in blogs %}
{% show_blog_post blog_post %}
{% endfor %}

{% paginate %}
{% else %}
{% trans "No blog posts yet." %}
{% endif %}


{% if blogs %}
{% trans "These are blog posts from everyone:" %}

   ** condition for passed data
**
  {% autopaginate blogs %}
{% for blog_post in blogs %}
{% show_blog_post blog_post %}
{% endfor %}
{% paginate %}

{% else %}
{% trans "No blog posts yet." %}
{% endif %}




--

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 validate a form field whose value can only increase?

2009-12-07 Thread Continuation
You're absolutely right.

I don't know what I was thinking.

Thanks!

On Dec 7, 8:42 pm, Shawn Milochik  wrote:
> On Dec 7, 2009, at 7:16 PM, Continuation wrote:
>
>
>
> > I thought if form.is_valid() returns False, Django would send a list
> > of the errors to browser. But that's not what happened here.
>
> Do you have anything like these in your template?
>
> {{ my_form.errors }}
>
> {{ my_form.field_name.errors }}
>
> 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.




Green hosting suggestions for Django?

2009-12-07 Thread Daniel Quinn
I'm working on a project for an environmentally-concious client that would 
like a planet-friendly host, preferably Canadian, though that's not required.

If that were it, I'd just google "green hosting" and be done with it, but 
since this is a Django project, I'd really appreciate some 
recommendations/suggestions from people who have actually deployed a Django 
site before I sign on.

Anyone have a story they'd like to share?

--

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 validate a form field whose value can only increase?

2009-12-07 Thread Shawn Milochik

On Dec 7, 2009, at 7:16 PM, Continuation wrote:
> 
> I thought if form.is_valid() returns False, Django would send a list
> of the errors to browser. But that's not what happened here.

Do you have anything like these in your template?

{{ my_form.errors }}

{{ my_form.field_name.errors }}

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.




CharField cannot have a "max_length" greater than 255 when using "unique=True"

2009-12-07 Thread germ
my platform: django 1.1.1, mysql 5.0.67, python 2.6.2

why does syncdb complain
 CharField cannot have a "max_length" greater than 255 when using
"unique=True"

when mysql 5.0.67 does allow greater tan 255? is there a way to
override or ignore this error?

this works in mysql
mysql> create table mbg_test_1 (id int(5), url varchar(760) not null,
primary key (id), unique (url));
Query OK, 0 rows affected (0.00 sec)

mysql> desc mbg_test_1;
+---+--+--+-+-+---+
| Field | Type | Null | Key | Default | Extra |
+---+--+--+-+-+---+
| id| int(5)   | NO   | PRI | 0   |   |
| url   | varchar(760) | NO   | UNI | NULL|   |
+---+--+--+-+-+---+
2 rows in set (0.00 sec)

mysql>

but a Model with
 url  = models.CharField('Full URL', max_length=760, unique=True)
yields an error from syncdb:
$ manage.py syncdb
Error: One or more models did not validate:
threats.threat: "url": CharField cannot have a "max_length" greater
than 255 when using "unique=True".
$

not sure why django hits this error since the true max length is 767,
not 255:

mysql> create table mbg_test_1 (url varchar(999) not null, unique
(url));
ERROR 1071 (42000): Specified key was too long; max key length is 767
bytes
mysql>

--

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.




admin app doesn't find template

2009-12-07 Thread Xbiton
Hi,

I'm new to django and I'm learning it trow a tutorial. Now I was
trying to access the admin interface after adding the
django.contib.flatpages to the installed app.

I did run the python manage.py syncdb and I've seen that the tables
for the admin an flatpages apps were created,
unfortunately when I try to access the admin  interface I recive an
error saiying me that ther's no template for the apps, even I added
the template folder ti the TEMPLATE_DIRS.

Now I wondering why, in the debug page of the django server I see that
to the template path django automatically adds admin/login.html even
the path I added to TEMPALTE_DIR was only /django-site/test/cms/
templates/.
practically the complete path
 django is searching is /django-site/test/cms/templates/admin/
login.html
is that right?

please help.

Xaver

Environment:

Request Method: GET
Request URL: http://localhost:8000/admin/
Django Version: 1.1.1
Python Version: 2.6.3
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.flatpages',
 'cms.frontend']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')

Template Loader Error:
Django tried loading these templates, in this order:
Using loader django.template.loaders.filesystem.load_template_source:
/Users/xaver/Documents/django-site/test/cms/templates/admin/login.html
(File does not exist)
Using loader
django.template.loaders.app_directories.load_template_source:



Traceback:
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/handlers/base.py" in get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/contrib/admin/sites.py" in wrapper
  196. return self.admin_view(view, cacheable)(*args,
**kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/views/decorators/cache.py" in
_wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/contrib/admin/sites.py" in inner
  185. return self.login(request)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/views/decorators/cache.py" in
_wrapped_view_func
  44. response = view_func(request, *args, **kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/contrib/admin/sites.py" in login
  288. return self.display_login_form(request, message)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/contrib/admin/sites.py" in
display_login_form
  389. context_instance=context_instance
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/shortcuts/__init__.py" in
render_to_response
  20. return HttpResponse(loader.render_to_string(*args,
**kwargs), **httpresponse_kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/template/loader.py" in render_to_string
  103. t = get_template(template_name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/template/loader.py" in get_template
  81. source, origin = find_template_source(template_name)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/template/loader.py" in
find_template_source
  74. raise TemplateDoesNotExist, name

Exception Type: TemplateDoesNotExist at /admin/
Exception Value: admin/login.html

--

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 change this function to use generic view

2009-12-07 Thread 邓超
Anyone? Please...

2009/12/7 一千瓦的刀狼 

> Hello? Anyone can help me?
>
> On Dec 6, 9:18 am, 邓超  wrote:
> > Hi all,
> >   I want to change below function to use the generic view function
> > update_object:
> >
> > @login_required
> > def edit_bug_page(request, bug_id = None):
> > if bug_id == None:
> > bugInstance = Bug()
> > else:
> > bugInstance = get_object_or_404(Bug, pk = bug_id)
> > members = bugInstance.project.member.order_by('member')
> >
> > if request.user not in members:
> > return HttpResponseRedirect('/bug/fail/')
> >
> > if request.method == 'POST':
> > form = BugForm(request.POST, instance = bugInstance)
> >
> > if form.is_valid():
> > bug = form.save()
> >
> > return HttpResponseRedirect('/bug/success/')
> > else:
> > form = BugForm(instance = bugInstance)
> >
> > variables = RequestContext(request, {'form': form})
> >
> > return render_to_response('add_bug.html', variables)
> >
> > But how to use the update_object function in my views.py? Someone can
> help
> > me? Thanks a lot!
> > --
> > Deng Chao
>
> --
>
> 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.
>
>
>


-- 
Deng Chao

--

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 validate a form field whose value can only increase?

2009-12-07 Thread Continuation
Hi,

Thank you very much for your help.

I used your form validation method.

The results is weird.

I tested it with a value lower than the previous value. But didn't see
any error message in my browser.

I stepped through the code using pdb. I could see that
forms.ValidationError("The amount in field yourfieldname may only
increase.")
was raised.

When I looked at the view that processes the form, I could also see
that form.is_valid() returned False.
Yet the next lines executed were:
variables = RequestContext(request, {'form': form})
return render_to_response('template.html', variables)
Those are the lines to be executed if there is no POST data.

I thought if form.is_valid() returns False, Django would send a list
of the errors to browser. But that's not what happened here.

Any ideas why?

On Dec 6, 11:20 pm, Shawn Milochik  wrote:
> On Dec 6, 2009, at 11:01 PM, Continuation wrote:
>
> > What do you mean by the __init__ of the model?
>
> Every models.Model object has an __init__ function, like any Python class. 
> You need to override it.
>
> Add this into your model (in your models.py):
>
>     def __init__(self, *args, **kwargs):
>
>         #make sure you call the default __init__, or stuff breaks.
>         super(YourModelName, self).__init__(*args, **kwargs)
>
>         #so we can tell if the new value for the field
>         #is increased upon save
>         self.old_value = self.field_name
>
> Then, you override the save function for the same model:
>
>     def save(self):
>
>         if self.old_value < self.fieldname:
>             raise ValueError('The field x can only increase.')
>
>         #go through with the standard 'save' stuff
>         #that is defined in models.Model class.
>         super(YourModelName, self).save()
>
> This way, your model will not allow itself to be saved if that value is 
> lowered. This doesn't directly answer your question, which was about form 
> validation. I don't know how to do it elegantly, so I hope someone else will 
> chime in. However, one thing you can do is to override the "clean" function 
> of your form for that particular field so that it pulls back an instance of 
> the old object and checks its own cleaned_data value against the value stored 
> in the database. Something like this:
>
> #within your forms.ModelForm for the model in question
>
>     def clean_yourfieldname(self):
>
>         yourfieldname = self.cleaned_data.get('yourfieldname', 0)
>         old_instance = YourModel.objects.get(pk = self.instance.pk)
>
>         if yourfieldname < old_instance.yourfieldname:
>             raise forms.ValidationError("The amount in field yourfieldname 
> may only increase.")
>
>         return yourfieldname
>
> To be fair, if you use this in your form validation, you don't really need 
> the stuff above in your model. However, if that is your business logic, then 
> it's a good idea to have it there in any case.
>
> 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: how can i find out that Development server is running or not?

2009-12-07 Thread Graham Dumpleton


On Dec 8, 9:45 am, Sameer Rahmani  wrote:
> i want to know just about development server . i mean i just want to know
> when my code run under development server:

The body of you post asked about both. :-)

> if development_server:
>       some code

If this is for debugging code, then you are perhaps better off looking
to see if DEBUG is set in Django settings. That way if really need to
you can still turn on debug in production Apache environment.

FWIW, if using mod_python or mod_wsgi there should be no __main__
module, thus:

  if '__main__' in sys.modules:
# not Apache mod_python or mod_wsgi

If you were using fastcgi/flup, would still be a '__main__' though.

Graham

--

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 i find out that Development server is running or not?

2009-12-07 Thread Sameer Rahmani
i want to know just about development server . i mean i just want to know
when my code run under development server:


if development_server:
  some code

--

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 i find out that Development server is running or not?

2009-12-07 Thread Graham Dumpleton


On Dec 7, 8:22 pm, Sameer Rahmani  wrote:
> hi
> how can i find out that my project ran under apache or development server ?

How are you running under Apache. Are you using mod_python, mod_wsgi,
fastcgi, something else?

One could try and look for the fingerprint of the development server,
or you can look for your target hosting mechanism under Apache. Not
know what you are using with Apache, can tell you how to do the
latter.

Graham

--

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 to change default template name for django.views.defaults.page_not_found ?

2009-12-07 Thread mateusz.szulc
>From Django Part 3 tutorial:
"The 404 view is also called if Django doesn't find a match after
checking every regular expression in the URLconf."

The 404 default view in django is defined as:
def page_not_found(request, template_name='404.html'):

How can I change the value of the template_name parameter?

--

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 get the last item of array in a built-in template tag?

2009-12-07 Thread Gaffar Overcomes
hey pete this does not work :S
negative index does not support error occured..

On Mon, Dec 7, 2009 at 12:38 AM, pjrhar...@gmail.com wrote:

> Try:
>
> {{ my_array|slice:"-1:" }}
>
> Pete
>
> --
>
> 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.
>
>
>


-- 
Gaffar Durmaz - Software Engineer
http://www.gaffarovercomes.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: How to create a form to edit an existing object without knowing the object's id?

2009-12-07 Thread Gaffar Overcomes
form = MyForm(instance=z)
if (request.method == 'POST'):
form = MyForm(request.POST, instance = z)
if (form.is_valid()):
z = form.save()
z.save()
return HttpResponseRedirect('redirect to success page')

return render_to_response("render to form page",{'form':form})

On Mon, Dec 7, 2009 at 5:58 PM, Daniel Roseman wrote:

> On Dec 7, 12:22 am, Continuation  wrote:
> > I have:
> >
> > class MyModel(models.Model):
> > fk= models.ForeignKey(AnotherModel)
> > field   = models.PositiveIntegerField()
> >
> > class MyForm((forms.ModelForm):
> > class Meta:
> > model   = MyModel
> >
> > Now I want to create a form to edit an existing MyModel instance. But
> > I don't know the pk of the instance. However I do now the value of fk
> > & field, which together should be enough to uniquely identify an
> > instance.
> >
> > So I do:
> > z = MyModel.objects.get(fk=o, field=f)
> > f = MyForm(instance=z)
> >
> > And the form f does have the correct data of z pre-populated.
> >
> > However when I submitted the form, a new MyModel object was created
> > instead of just updating z.
> >
> > What do I need to do to create a form that would update z?
>
> You don't need to do anything. If you've correctly passed in the
> instance, it will always edit the existing one. I imagine that you've
> used the instance when creating the form on GET, but have forgotten to
> do so when creating it on POST:
>
>f = MyForm(request.POST, instance=z)
>
> --
> 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.
>
>
>


-- 
Gaffar Durmaz - Software Engineer
http://www.gaffarovercomes.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: Pydev + Django + Ubuntu 9.10

2009-12-07 Thread Brian McKeever
I'm using django from the repositories.
Installed this way:
http://docs.djangoproject.com/en/dev/topics/install/#installing-development-version

I configured my interpretor in eclipse by doing this:
"Now, on to re-configure the pydev interpreter to add those new
paths... I'm kind of lazy, so, usually I just remove the interpreter
and add it again, instead of figuring out just the new paths (I also
thinks it's safer, as it gets all the folders it finds in the
pythonpath automatically). "

From:
http://pydev.blogspot.com/2006/09/configuring-pydev-to-work-with-django.html



On Dec 7, 8:17 am, turkan  wrote:
> Hello Brian.
>
> Strange, I am also using Eclipse downloaded from eclipse.org. Did you
> add any special folders to the PYTHONPATH? Are you using django from
> the Ubuntu repositories?
>
> On Dec 7, 6:06 am, Brian McKeever  wrote:
>
> > I was having the same trouble you are when I installed eclipse from
> > the repository.
> > I fixed it by downloading it again from the 
> > websitehttp://www.eclipse.org/downloads/
> > (Eclipse IDE for C/C++ Developers (79 MB) is the one I picked
> > specifically).

--

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: ManyToOne to auth.models.User

2009-12-07 Thread Carl Zmola


TiNo wrote:
> On Sun, Nov 15, 2009 at 09:31, Dennis Kaarsemaker 
> wrote:
>
>   
>> On za, 2009-11-14 at 15:53 -0800, TiNo wrote:
>>
>> 
>>> In my apps, Users of the app participate in a certain Year. I would
>>> like a Year to continue a ManyToOne relationship with a User. 
Don't you need a many to many relationship anyway?  Will a user only be 
limited to one year?

I added a user profile to add a many to many field to user.  I just need 
to figure out how to get it to show up in the admin for my "year" model. 
It shows up fine in the user model now.

Carl

-- 
Carl Zmola
301-562-1900 x315
czm...@woti.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: insert into data field of model based on other data field values

2009-12-07 Thread Shawn Milochik
Easy to do:

Just override the save() function of the model.

class MyModel(models.Model):

def save(self, **kwargs):

#add your logic here

super(MyModel, self).save(**kwargs)

--

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.




insert into data field of model based on other data field values

2009-12-07 Thread rc
I am trying to figure out the best way to go about this. Here is the
scenario:

I have five fields in my model that the user will set from the admin.
When they save the model I want to insert a value into another field
of the model based on these values.

Where/How is the best place to handle this.

Here are the specifics:

class Job(models.Model):
job_id = models.AutoField(primary_key=True)
job_name = models.CharField(max_length=50)
server = models.CharField(max_length=25)
minute = models.CharField(max_length=10, choices = 
u.min_choices())
hour = models.CharField(max_length=10, choices = 
u.hour_choices())
day_of_month = models.CharField(max_length=10, choices =
u.dom_choices())
month = models.CharField(max_length=10, choices = 
u.mon_choices())
day_of_week = models.CharField(max_length=10, choices = 
u.dow_choices
())
next_run_time = models.DateTimeField(blank=True)

What I want to do is based on the values of minute, hour,
day_of_month, month and day_of_week I want to calculate the
next_run_time and save that to the Job model.

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.




filter foreign key field in inline formset

2009-12-07 Thread cerberos
One of the fields in an inline formset has a foreign key to another
model, how can I filter it?

I'm building a library system, the models are loans, loan items and
book instances. I don't want books that are currently out on loan to
be available on the loan items dropdown list.

--

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: Custom get/set from model

2009-12-07 Thread Waqqas Jabbar
I want that I could override get/set on a field of my model. I want to
redirect get/set
to another field of some other model.

On Mon, Dec 7, 2009 at 8:47 PM, Daniel Hirsch  wrote:

> I'm not clear what you're asking. Do you want a custom get/set on a
> particular database field in one of your models (tables)?
>
> On Dec 7, 1:18 am, Waqqas Jabbar  wrote:
> > Peace to all,
> >
> > I want to do a custom implementation of "get" and "set" functions of a
> > database model. Do I ve to write a custom model manager or derive a class
> > from models.Model ?
> > Is it possible to write custom "get" and "set" functions for a model
> field ?
> >
> > goto
>
> --
>
> 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.




Re: Show additional user information in admin

2009-12-07 Thread Carl Zmola

bax...@gretschpages.com wrote:
>> You can do that by creating an 
>> InlineModelAdmin:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodelad...
>> 
>
> How, exactly? I tried this, with no luck:
>
> from user_profiles.models import Profile
> from django.contrib.auth.admin import UserAdmin
>
> class ProfileInline(admin.TabularInline):
> model = Profile
>
> UserAdmin.inlines = [ProfileInline]
>   
In the  admin for my app, I added the following code.  It works, and I 
can't remember where I found it but it was someone's blog.

#
# Make our profile show up in the user admin
#
admin.site.unregister(User)

class UserProfileInline(admin.StackedInline):
model = UserProfile
filter_horizontal = ['myField']

class UserProfileAdmin(UserAdmin):
inlines = [UserProfileInline]


-- 
Carl Zmola
301-562-1900 x315
czm...@woti.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: model design problem

2009-12-07 Thread Bill Freeman
Or there's overriding the metaclass...

On Mon, Dec 7, 2009 at 12:39 PM, Bill Freeman  wrote:
> Hmmm.  Probably just as ugly, and untested, but:
>
> class A(basemodel):
>    for o in range(MAXNUMREDPORTS):
>         for i in (1,2):
>             locals()["Port%d_redfield%d" % (o+1, i)] = models.FloatField()
> ...
>
> On Mon, Dec 7, 2009 at 12:10 PM, Daniel Goertzen
>  wrote:
>> Okay, I explored model generation a bit and found an approach that wasn't
>> too offensive.  For those that are trying to solve the same problem that I
>> am, here is what I came up with:
>>
>> def red_port(prefix):
>>    return """
>> %(prefix)sredfield1 = models.FloatField()
>> %(prefix)sredfield2 = models.FloatField()
>> """ % {'prefix':prefix}
>> class A(basemodel):
>>   exec red_port("Port1_")
>>   exec red_port("Port2_")
>>   ...
>>
>> ...which yields sql something like...
>> CREATE TABLE `A` (
>>     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
>>     ...
>>     `Port1_redfield1` double precision,
>>     `Port1_redfield2` double precision,
>>     `Port2_redfield1` double precision,
>>     `Port2_redfield2` double precision,
>> );
>>
>>
>> I feel DRY again, and only a little bit dirty. :)
>> Dan.
>>
>> On Mon, Dec 7, 2009 at 9:12 AM, Dan  wrote:
>>>
>>> I am relatively new to django and relational databases, and need some
>>> Model advice.
>>>
>>> I have a family of network products each with a different combination
>>> of ports.. I will call them red ports and green ports.  For example,
>>> product A will have its own Model and could have 2 red ports and 1
>>> green port.  Product B is similar, but has only 3 green ports.
>>> My current approach is to use an abstract base Model, and then create
>>> Models for products A and B that contain all needed fields, for
>>> example:
>>>
>>> class A(basemodel):
>>>   Port1_redfield1 = ...
>>>   Port1_redfield2 = ...
>>>   ...
>>>   Port2_redfield1 = ...
>>>   Port2_redfield2 = ...
>>>   ...
>>>
>>>
>>> Yuck, not very DRY at all.  I also tried to create a red port Model
>>> and green port Model and use one to one fields to connect them to
>>> products.  The problem with this is that I could not figure out how to
>>> encapsulate the ports; I always had to worry about creating, linking
>>> and deleting port objects when dealing with products.  Not acceptable.
>>>
>>> I also thought about other tricks like generating my models.py file
>>> from a generator program, and dynamic insertion of attributes into
>>> existing classes.  I really would rather not go there.
>>>
>>> So, my question:  Is there a nice DRY way to get the kind of
>>> structured composition that I want?
>>>
>>> Side question: Is there another python ORM that could address my need
>>> better?
>>>
>>> Thanks,
>>> Dan.
>>
>>
>> --
>> Daniel Goertzen
>> -
>> d...@networkintegritysystems.com (work)
>> daniel.goert...@gmail.com (home)
>> -
>> 1 204 272 6149 (home/office)
>> 1 204 470 8360 (mobile)
>> -
>>
>>
>>
>> --
>>
>> 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.




Re: model design problem

2009-12-07 Thread Bill Freeman
Hmmm.  Probably just as ugly, and untested, but:

class A(basemodel):
for o in range(MAXNUMREDPORTS):
 for i in (1,2):
 locals()["Port%d_redfield%d" % (o+1, i)] = models.FloatField()
...

On Mon, Dec 7, 2009 at 12:10 PM, Daniel Goertzen
 wrote:
> Okay, I explored model generation a bit and found an approach that wasn't
> too offensive.  For those that are trying to solve the same problem that I
> am, here is what I came up with:
>
> def red_port(prefix):
>    return """
> %(prefix)sredfield1 = models.FloatField()
> %(prefix)sredfield2 = models.FloatField()
> """ % {'prefix':prefix}
> class A(basemodel):
>   exec red_port("Port1_")
>   exec red_port("Port2_")
>   ...
>
> ...which yields sql something like...
> CREATE TABLE `A` (
>     `id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
>     ...
>     `Port1_redfield1` double precision,
>     `Port1_redfield2` double precision,
>     `Port2_redfield1` double precision,
>     `Port2_redfield2` double precision,
> );
>
>
> I feel DRY again, and only a little bit dirty. :)
> Dan.
>
> On Mon, Dec 7, 2009 at 9:12 AM, Dan  wrote:
>>
>> I am relatively new to django and relational databases, and need some
>> Model advice.
>>
>> I have a family of network products each with a different combination
>> of ports.. I will call them red ports and green ports.  For example,
>> product A will have its own Model and could have 2 red ports and 1
>> green port.  Product B is similar, but has only 3 green ports.
>> My current approach is to use an abstract base Model, and then create
>> Models for products A and B that contain all needed fields, for
>> example:
>>
>> class A(basemodel):
>>   Port1_redfield1 = ...
>>   Port1_redfield2 = ...
>>   ...
>>   Port2_redfield1 = ...
>>   Port2_redfield2 = ...
>>   ...
>>
>>
>> Yuck, not very DRY at all.  I also tried to create a red port Model
>> and green port Model and use one to one fields to connect them to
>> products.  The problem with this is that I could not figure out how to
>> encapsulate the ports; I always had to worry about creating, linking
>> and deleting port objects when dealing with products.  Not acceptable.
>>
>> I also thought about other tricks like generating my models.py file
>> from a generator program, and dynamic insertion of attributes into
>> existing classes.  I really would rather not go there.
>>
>> So, my question:  Is there a nice DRY way to get the kind of
>> structured composition that I want?
>>
>> Side question: Is there another python ORM that could address my need
>> better?
>>
>> Thanks,
>> Dan.
>
>
> --
> Daniel Goertzen
> -
> d...@networkintegritysystems.com (work)
> daniel.goert...@gmail.com (home)
> -
> 1 204 272 6149 (home/office)
> 1 204 470 8360 (mobile)
> -
>
>
>
> --
>
> 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.




Re: model design problem

2009-12-07 Thread Bill Freeman
Unless I'm very confused, django will happily delete your related
objects (since they
don't have anything to relate to anymore).  Many to many would be more
problematic.

As far as creating a set of ports, you were stuck with that anyway, if
I understand
your original approach correctly.  Even if your model had N red port slots and M
green port slots, with flags as to whether this product has that port,
(each product is
an instance of "A", no?), you have to fill in the flag and any
individual data (port address,
for example) when you create the instance for a product.  The only
difference with the
many to one is that you call the port constructor, passing the product
instance, and
after the fields are filled, you call the save method.  In turn, you
get enumeration of the
set of ports that you actually have in this product for free from the
framework, rather
than having to write code to skip the ports not present in this
product.  Probably not
useful in your case, but you can adjust the set of ports on a product
"later" with the
foreign key scheme.

If, on the other hand, you were going to make a model per product
type, forget all that
I said.

On Mon, Dec 7, 2009 at 11:56 AM, Daniel Goertzen
 wrote:
> Thanks for the reply Bill.  The problem I had with that approach is that
> after creating the product I have to worry about creating red and green
> ports.  Likewise, upon deletion, I have to mop up the ports.  Looking
> through the documentation, I did not find a way to bury this behavior in the
> Model.
> Hmm, abstract base class for the ports is an interesting idea.  Could be
> useful at template time.
> Dan.
>
> On Mon, Dec 7, 2009 at 10:07 AM, Bill Freeman  wrote:
>>
>> I'm not clear on what you need to store, so I'll assume that you have
>> individual
>> data to store for each port of each type, and it is unrelated to data
>> stored for
>> another instance of the same or a different product.
>>
>> What comes to mind is that there is a "Product" model and a "Port" model
>> (or if
>> red and green ports carry different fields, both a "RedPort" and a
>> "GreenPort"
>> model).  Ports have a foreign key relationship on Products.  Now an
>> assortment
>> of Port instances can be assigned to a Product instance.  Django will
>> created
>> an accessor (or accessors) on the Product model for obtaining a query set
>> of
>> the Port instances associated with a given Product instance.  (If you want
>> separate RedPort and GreenPort models, but they share a lot of behaviours
>> and/or fields, you may want to look at Django's abstract base class
>> mechanism,
>> but it takes a bit to get right, in my experience.)
>>
>>
>> On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
>> > I am relatively new to django and relational databases, and need some
>> > Model advice.
>> >
>> > I have a family of network products each with a different combination
>> > of ports.. I will call them red ports and green ports.  For example,
>> > product A will have its own Model and could have 2 red ports and 1
>> > green port.  Product B is similar, but has only 3 green ports.
>> > My current approach is to use an abstract base Model, and then create
>> > Models for products A and B that contain all needed fields, for
>> > example:
>> >
>> > class A(basemodel):
>> >   Port1_redfield1 = ...
>> >   Port1_redfield2 = ...
>> >   ...
>> >   Port2_redfield1 = ...
>> >   Port2_redfield2 = ...
>> >   ...
>> >
>> >
>> > Yuck, not very DRY at all.  I also tried to create a red port Model
>> > and green port Model and use one to one fields to connect them to
>> > products.  The problem with this is that I could not figure out how to
>> > encapsulate the ports; I always had to worry about creating, linking
>> > and deleting port objects when dealing with products.  Not acceptable.
>> >
>> > I also thought about other tricks like generating my models.py file
>> > from a generator program, and dynamic insertion of attributes into
>> > existing classes.  I really would rather not go there.
>> >
>> > So, my question:  Is there a nice DRY way to get the kind of
>> > structured composition that I want?
>> >
>> > Side question: Is there another python ORM that could address my need
>> > better?
>> >
>> > Thanks,
>> > Dan.
>> >
>> > --
>> >
>> > 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/

Re: model design problem

2009-12-07 Thread Preston Holmes


On Dec 7, 8:56 am, Daniel Goertzen  wrote:
> Thanks for the reply Bill.  The problem I had with that approach is that
> after creating the product I have to worry about creating red and green
> ports.  Likewise, upon deletion, I have to mop up the ports.  Looking
> through the documentation, I did not find a way to bury this behavior in the
> Model.

I think you misunderstand - I think the suggestion is, and I agree
with it, is to have your specific Products represented as instances in
the database, not as code objects.

If the products are similar enough - have one "Product" model with
fields like, name, modelnumber etc

Then have one "Port" Model, that might have fields like "color" etc

Then you create an instance of a product and related port instances in
the database, not in model code.

Yes you have to define the unique combinations, but you have to do
this once somewhere.

Any place you need to refer to that product model, you use a
foreignkey to that product _instance_ in the database.

-Preston

>
> Hmm, abstract base class for the ports is an interesting idea.  Could be
> useful at template time.
>
> Dan.
>
>
>
>
>
> On Mon, Dec 7, 2009 at 10:07 AM, Bill Freeman  wrote:
> > I'm not clear on what you need to store, so I'll assume that you have
> > individual
> > data to store for each port of each type, and it is unrelated to data
> > stored for
> > another instance of the same or a different product.
>
> > What comes to mind is that there is a "Product" model and a "Port" model
> > (or if
> > red and green ports carry different fields, both a "RedPort" and a
> > "GreenPort"
> > model).  Ports have a foreign key relationship on Products.  Now an
> > assortment
> > of Port instances can be assigned to a Product instance.  Django will
> > created
> > an accessor (or accessors) on the Product model for obtaining a query set
> > of
> > the Port instances associated with a given Product instance.  (If you want
> > separate RedPort and GreenPort models, but they share a lot of behaviours
> > and/or fields, you may want to look at Django's abstract base class
> > mechanism,
> > but it takes a bit to get right, in my experience.)
>
> > On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
> > > I am relatively new to django and relational databases, and need some
> > > Model advice.
>
> > > I have a family of network products each with a different combination
> > > of ports.. I will call them red ports and green ports.  For example,
> > > product A will have its own Model and could have 2 red ports and 1
> > > green port.  Product B is similar, but has only 3 green ports.
> > > My current approach is to use an abstract base Model, and then create
> > > Models for products A and B that contain all needed fields, for
> > > example:
>
> > > class A(basemodel):
> > >   Port1_redfield1 = ...
> > >   Port1_redfield2 = ...
> > >   ...
> > >   Port2_redfield1 = ...
> > >   Port2_redfield2 = ...
> > >   ...
>
> > > Yuck, not very DRY at all.  I also tried to create a red port Model
> > > and green port Model and use one to one fields to connect them to
> > > products.  The problem with this is that I could not figure out how to
> > > encapsulate the ports; I always had to worry about creating, linking
> > > and deleting port objects when dealing with products.  Not acceptable.
>
> > > I also thought about other tricks like generating my models.py file
> > > from a generator program, and dynamic insertion of attributes into
> > > existing classes.  I really would rather not go there.
>
> > > So, my question:  Is there a nice DRY way to get the kind of
> > > structured composition that I want?
>
> > > Side question: Is there another python ORM that could address my need
> > > better?
>
> > > Thanks,
> > > Dan.
>
> > > --
>
> > > 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 > groups.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 > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> Daniel Goertzen
> -
> d...@networkintegritysystems.com (work)
> daniel.goert...@gmail.com (home)
> -
> 1 204 272 6149 (home/office)
> 1 204 470 8360 (mobile)
> -

--

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 em

Re: model design problem

2009-12-07 Thread Daniel Goertzen
Okay, I explored model generation a bit and found an approach that wasn't
too offensive.  For those that are trying to solve the same problem that I
am, here is what I came up with:


def red_port(prefix):
   return """
%(prefix)sredfield1 = models.FloatField()
%(prefix)sredfield2 = models.FloatField()
""" % {'prefix':prefix}

class A(basemodel):
  exec red_port("Port1_")
  exec red_port("Port2_")
  ...


...which yields sql something like...

CREATE TABLE `A` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
...
`Port1_redfield1` double precision,
`Port1_redfield2` double precision,
`Port2_redfield1` double precision,
`Port2_redfield2` double precision,
);



I feel DRY again, and only a little bit dirty. :)

Dan.


On Mon, Dec 7, 2009 at 9:12 AM, Dan  wrote:

> I am relatively new to django and relational databases, and need some
> Model advice.
>
> I have a family of network products each with a different combination
> of ports.. I will call them red ports and green ports.  For example,
> product A will have its own Model and could have 2 red ports and 1
> green port.  Product B is similar, but has only 3 green ports.
> My current approach is to use an abstract base Model, and then create
> Models for products A and B that contain all needed fields, for
> example:
>
> class A(basemodel):
>   Port1_redfield1 = ...
>   Port1_redfield2 = ...
>   ...
>   Port2_redfield1 = ...
>   Port2_redfield2 = ...
>   ...
>
>
> Yuck, not very DRY at all.  I also tried to create a red port Model
> and green port Model and use one to one fields to connect them to
> products.  The problem with this is that I could not figure out how to
> encapsulate the ports; I always had to worry about creating, linking
> and deleting port objects when dealing with products.  Not acceptable.
>
> I also thought about other tricks like generating my models.py file
> from a generator program, and dynamic insertion of attributes into
> existing classes.  I really would rather not go there.
>
> So, my question:  Is there a nice DRY way to get the kind of
> structured composition that I want?
>
> Side question: Is there another python ORM that could address my need
> better?
>
> Thanks,
> Dan.




-- 
Daniel Goertzen
-
d...@networkintegritysystems.com (work)
daniel.goert...@gmail.com (home)
-
1 204 272 6149 (home/office)
1 204 470 8360 (mobile)
-

--

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: browser input and strings

2009-12-07 Thread rvandam
>         browse_lijst = Nl.objects.filter(lijst__slug=browse)
>
> Does that solve your problem?
> --
> DR.

Yes

Thanks a lot :-)

Rob

--

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: model design problem

2009-12-07 Thread Daniel Goertzen
Thanks for the reply Bill.  The problem I had with that approach is that
after creating the product I have to worry about creating red and green
ports.  Likewise, upon deletion, I have to mop up the ports.  Looking
through the documentation, I did not find a way to bury this behavior in the
Model.

Hmm, abstract base class for the ports is an interesting idea.  Could be
useful at template time.

Dan.

On Mon, Dec 7, 2009 at 10:07 AM, Bill Freeman  wrote:

> I'm not clear on what you need to store, so I'll assume that you have
> individual
> data to store for each port of each type, and it is unrelated to data
> stored for
> another instance of the same or a different product.
>
> What comes to mind is that there is a "Product" model and a "Port" model
> (or if
> red and green ports carry different fields, both a "RedPort" and a
> "GreenPort"
> model).  Ports have a foreign key relationship on Products.  Now an
> assortment
> of Port instances can be assigned to a Product instance.  Django will
> created
> an accessor (or accessors) on the Product model for obtaining a query set
> of
> the Port instances associated with a given Product instance.  (If you want
> separate RedPort and GreenPort models, but they share a lot of behaviours
> and/or fields, you may want to look at Django's abstract base class
> mechanism,
> but it takes a bit to get right, in my experience.)
>
>
> On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
> > I am relatively new to django and relational databases, and need some
> > Model advice.
> >
> > I have a family of network products each with a different combination
> > of ports.. I will call them red ports and green ports.  For example,
> > product A will have its own Model and could have 2 red ports and 1
> > green port.  Product B is similar, but has only 3 green ports.
> > My current approach is to use an abstract base Model, and then create
> > Models for products A and B that contain all needed fields, for
> > example:
> >
> > class A(basemodel):
> >   Port1_redfield1 = ...
> >   Port1_redfield2 = ...
> >   ...
> >   Port2_redfield1 = ...
> >   Port2_redfield2 = ...
> >   ...
> >
> >
> > Yuck, not very DRY at all.  I also tried to create a red port Model
> > and green port Model and use one to one fields to connect them to
> > products.  The problem with this is that I could not figure out how to
> > encapsulate the ports; I always had to worry about creating, linking
> > and deleting port objects when dealing with products.  Not acceptable.
> >
> > I also thought about other tricks like generating my models.py file
> > from a generator program, and dynamic insertion of attributes into
> > existing classes.  I really would rather not go there.
> >
> > So, my question:  Is there a nice DRY way to get the kind of
> > structured composition that I want?
> >
> > Side question: Is there another python ORM that could address my need
> > better?
> >
> > Thanks,
> > Dan.
> >
> > --
> >
> > 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.
>
>
>


-- 
Daniel Goertzen
-
d...@networkintegritysystems.com (work)
daniel.goert...@gmail.com (home)
-
1 204 272 6149 (home/office)
1 204 470 8360 (mobile)
-

--

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: browser input and strings

2009-12-07 Thread Daniel Roseman
On Dec 7, 4:35 pm, rvandam  wrote:
> Sorry for the confusion. Here are both complete models:
>
> class Nl(models.Model):

>         lijst = models.ForeignKey('Menu_nl')
>         type = models.ForeignKey('Type_nl')
>         perceel = models.ForeignKey('Perceel_nl')
>         plaatshuur = models.ForeignKey('Plaatshuur_nl')


> class Menu_nl(models.Model):
>         categorie = models.CharField(max_length=50)
>         order = models.IntegerField()
>         slug = models.SlugField()


OK now we're getting somewhere.

So, as I understand it, the problem is this bit of code you posted way
back in the first message:

def browse_page(request, browse):
menu = get_list_or_404(Menu_nl, slug=browse)
browse_lijst = Nl.objects.filter(lijst=browse)

What you're doing here is comparing 'browse', a string, with the
'lijst' field, which is a Menu_nl object. Obviously, they don't match.
Presumably what you actually want to match is the *slug* field of the
Menu_nl object. Which is easy:

browse_lijst = Nl.objects.filter(lijst__slug=browse)

Does that solve your problem?
--
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: browser input and strings

2009-12-07 Thread rvandam
Sorry for the confusion. Here are both complete models:

class Nl(models.Model):
publiceren = models.BooleanField()
titel = models.CharField(max_length=60)
tekst = models.TextField()
prijs = models.CharField(max_length=12)
#tekst_html = models.TextField(editable=False, blank=True)
slug = models.SlugField(max_length=60)
kort = models.TextField()
thumb = models.ImageField(upload_to='verkoop/thumb/%Y/%m/%d',
default='verkoop/thumb/geen_afbeelding.jpg', blank=True)
remove_thumb = models.BooleanField()
plaatje1 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje1 = models.BooleanField()
plaatje2 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje2 = models.BooleanField()
plaatje3 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje3 = models.BooleanField()
plaatje4 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje4 = models.BooleanField()
plaatje5 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje5 = models.BooleanField()
plaatje6 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje6 = models.BooleanField()
pdf = models.FileField(upload_to='verkoop/%Y/%m/%d',blank=True)
remove_pdf = models.BooleanField()
youtube = models.CharField(max_length=700, blank=True)
lijst = models.ForeignKey('Menu_nl')
type = models.ForeignKey('Type_nl')
perceel = models.ForeignKey('Perceel_nl')
plaatshuur = models.ForeignKey('Plaatshuur_nl')
def __unicode__(self):
#return '%s %s' %(self.titel, self.tekst)
return self.titel
def save (self, size=(125, 93), size1=(400,300), size2=(200,150)):
super(Nl, self).save()
if self.thumb:
filename = self.thumb.path
image = Image.open(filename)
image.thumbnail(size, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.plaatje1:
filename = self.plaatje1.path
image = Image.open(filename)
image.thumbnail(size1, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.plaatje2:
filename = self.plaatje2.path
image = Image.open(filename)
image.thumbnail(size1, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.plaatje3:
filename = self.plaatje3.path
image = Image.open(filename)
image.thumbnail(size1, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.plaatje4:
filename = self.plaatje4.path
image = Image.open(filename)
image.thumbnail(size1, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.plaatje5:
filename = self.plaatje5.path
image = Image.open(filename)
image.thumbnail(size1, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.plaatje6:
filename = self.plaatje6.path
image = Image.open(filename)
image.thumbnail(size1, Image.ANTIALIAS)
image.save(filename)
super(Nl, self).save()
if self.remove_thumb:
self.thumb = ""
self.remove_thumb = False
super(Nl, self).save()
if self.remove_plaatje1:
self.plaatje1 = ""
self.remove_plaatje1 = False
super(Nl, self).save()
if self.remove_plaatje2:
self.plaatje2 = ""
self.remove_plaatje2 = False
super(Nl, self).save()
if self.remove_plaatje3:
self.plaatje3 = ""
self.remove_plaatje3 = False
super(Nl, self).save()
if self.remove_plaatje4:
self.plaatje4 = ""
self.remove_plaatje4 = False
super(Nl, self).save()
if self.remove_plaatje5:
self.plaatje5 = ""
self.remove_plaatje5 = False
super(Nl

Re: model design problem

2009-12-07 Thread Bill Freeman
I'm not clear on what you need to store, so I'll assume that you have individual
data to store for each port of each type, and it is unrelated to data stored for
another instance of the same or a different product.

What comes to mind is that there is a "Product" model and a "Port" model (or if
red and green ports carry different fields, both a "RedPort" and a "GreenPort"
model).  Ports have a foreign key relationship on Products.  Now an assortment
of Port instances can be assigned to a Product instance.  Django will created
an accessor (or accessors) on the Product model for obtaining a query set of
the Port instances associated with a given Product instance.  (If you want
separate RedPort and GreenPort models, but they share a lot of behaviours
and/or fields, you may want to look at Django's abstract base class mechanism,
but it takes a bit to get right, in my experience.)


On Mon, Dec 7, 2009 at 10:12 AM, Dan  wrote:
> I am relatively new to django and relational databases, and need some
> Model advice.
>
> I have a family of network products each with a different combination
> of ports.. I will call them red ports and green ports.  For example,
> product A will have its own Model and could have 2 red ports and 1
> green port.  Product B is similar, but has only 3 green ports.
> My current approach is to use an abstract base Model, and then create
> Models for products A and B that contain all needed fields, for
> example:
>
> class A(basemodel):
>   Port1_redfield1 = ...
>   Port1_redfield2 = ...
>   ...
>   Port2_redfield1 = ...
>   Port2_redfield2 = ...
>   ...
>
>
> Yuck, not very DRY at all.  I also tried to create a red port Model
> and green port Model and use one to one fields to connect them to
> products.  The problem with this is that I could not figure out how to
> encapsulate the ports; I always had to worry about creating, linking
> and deleting port objects when dealing with products.  Not acceptable.
>
> I also thought about other tricks like generating my models.py file
> from a generator program, and dynamic insertion of attributes into
> existing classes.  I really would rather not go there.
>
> So, my question:  Is there a nice DRY way to get the kind of
> structured composition that I want?
>
> Side question: Is there another python ORM that could address my need
> better?
>
> Thanks,
> Dan.
>
> --
>
> 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.




Re: browser input and strings

2009-12-07 Thread Daniel Roseman
On Dec 7, 3:11 pm, rvandam  wrote:
> Hi Shawn thanks for your reply.
>
> I have some categories, with multiple items per category. If a user
> entershttp://mysite.com/items-from-100-to-1000I want a short
> description of all items in that category listed.
>
> I have done this so far with:
>    {% for x in browse_lijst %}
>  {% ifequal x.lijst.__str__ browse.__str__ %}
> {{x.titel}}
>
> etc. etc.
>
> This works with Django 1.0 but gives problems when i try to upgrade.
>
> Here is the model:
> class Nl(models.Model):
>         publiceren = models.BooleanField()
>         titel = models.CharField(max_length=60)
>         tekst = models.TextField()
>         prijs = models.CharField(max_length=12)
>         slug = models.SlugField(max_length=60)
>         kort = models.TextField()
>         thumb = models.ImageField(upload_to='verkoop/thumb/%Y/%m/%d',
> default='verkoop/thumb/geen_afbeelding.jpg', blank=True)
>         remove_thumb = models.BooleanField()
>         plaatje1 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
> blank=True)
>         remove_plaatje1 = models.BooleanField()
> etc.etc.
>
> Please let me know if you need more info

This model doesn't seem to have a `lijst` field. Please show the real
model.
--
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 create a form to edit an existing object without knowing the object's id?

2009-12-07 Thread Daniel Roseman
On Dec 7, 12:22 am, Continuation  wrote:
> I have:
>
> class MyModel(models.Model):
>     fk                    = models.ForeignKey(AnotherModel)
>     field               = models.PositiveIntegerField()
>
> class MyForm((forms.ModelForm):
>     class Meta:
>         model   = MyModel
>
> Now I want to create a form to edit an existing MyModel instance. But
> I don't know the pk of the instance. However I do now the value of fk
> & field, which together should be enough to uniquely identify an
> instance.
>
> So I do:
> z = MyModel.objects.get(fk=o, field=f)
> f = MyForm(instance=z)
>
> And the form f does have the correct data of z pre-populated.
>
> However when I submitted the form, a new MyModel object was created
> instead of just updating z.
>
> What do I need to do to create a form that would update z?

You don't need to do anything. If you've correctly passed in the
instance, it will always edit the existing one. I imagine that you've
used the instance when creating the form on GET, but have forgotten to
do so when creating it on POST:

f = MyForm(request.POST, instance=z)

--
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 create a form to edit an existing object without knowing the object's id?

2009-12-07 Thread Bill Freeman
Off the top of my head, you have three choices.

1. Create a hidden field to carry the id (yes, you do know it once you've done
that query - it's z.id or z.pk).

2. (My favorite) encode the id as part of the url or as a query parameter in the
action attribute of your form.  Then access it in the view via
urlpattern or the request
object, respectively.

In either case above you use the id to fetch the correct instance.

3. Redo your query based on fk and field, which must be carried in the form, and
not changed, so that you'll be able to get them from the request.

In any case, in the request method is post path, initialize your form
from both the
instance and the POST parameters, check for valid, and if so call the
save method.
This layout is nearly boilerplate, see the forms documentation of the
documentation
page for samples.

On Sun, Dec 6, 2009 at 7:22 PM, Continuation  wrote:
> I have:
>
> class MyModel(models.Model):
>    fk                    = models.ForeignKey(AnotherModel)
>    field               = models.PositiveIntegerField()
>
> class MyForm((forms.ModelForm):
>    class Meta:
>        model   = MyModel
>
> Now I want to create a form to edit an existing MyModel instance. But
> I don't know the pk of the instance. However I do now the value of fk
> & field, which together should be enough to uniquely identify an
> instance.
>
> So I do:
> z = MyModel.objects.get(fk=o, field=f)
> f = MyForm(instance=z)
>
> And the form f does have the correct data of z pre-populated.
>
> However when I submitted the form, a new MyModel object was created
> instead of just updating z.
>
> What do I need to do to create a form that would update z?
>
> --
>
> 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.




Re: Custom get/set from model

2009-12-07 Thread Daniel Hirsch
I'm not clear what you're asking. Do you want a custom get/set on a
particular database field in one of your models (tables)?

On Dec 7, 1:18 am, Waqqas Jabbar  wrote:
> Peace to all,
>
> I want to do a custom implementation of "get" and "set" functions of a
> database model. Do I ve to write a custom model manager or derive a class
> from models.Model ?
> Is it possible to write custom "get" and "set" functions for a model field ?
>
> goto

--

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: model design problem

2009-12-07 Thread Daniel Goertzen
Each port would have about a half-dozen fields, and different port types are
totally different from one another.  I won't be querying port fields.

I've thought about your JSON field trick before, but not with the nice
wrapper methods.  Good idea, thanks!

The solution does have flaws, but if nothing better comes up I might just go
this way.

Thanks again,
Dan.


On Mon, Dec 7, 2009 at 9:20 AM, Shawn Milochik  wrote:

> What kind of information will the database have to store about the ports
> themselves?
>
> How will you need to be able to filter querysets by information in the port
> fields, if at all?
>
> I'm going to throw this one solution out there, but depending on your needs
> it may not fit:
>
> Create a red_ports column and a green_ports column in your model. Each one
> will contain serialized JSON. You can just dump a Python dictionary into
> those fields with simplejson.dumps, and retrieve the data with
> simplejson.loads. Then, you add methods to your model which you can use in
> the views that deal with the model.
>
>
>
>
>
> Here are a couple of lines of code from one of my models. I'm storing the
> hashes of old passwords to prevent people from re-using passwords.
>
> #field definition in model
> prev_passwords = models.TextField(default = '{}')
>
> I then get and set the values like this:
>
>def _get_prev_passwords(self):
>return simplejson.loads(self.prev_passwords)
>
>def _set_prev_passwords(self, pw_dict):
>self.prev_passwords = simplejson.dumps(pw_dict)
>
>previous_passwords = property(_get_prev_passwords, _set_prev_passwords)
>
> This way, my model's .previous_passwords attribute is available in my
> views, and the serialization is transparent.
>
>
>
>
> So, your Python dictionaries can contain all kinds of data about the red
> and green ports, and contain entries for any number of ports. Your models
> remain clean.
> The biggest flaw in this method is that, if you need to select a set of
> products based on an attribute of a port, you'll have to jump through hoops
> to make it happen.
>
> 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.
>
>
>


-- 
Daniel Goertzen
-
d...@networkintegritysystems.com (work)
daniel.goert...@gmail.com (home)
-
1 204 272 6149 (home/office)
1 204 470 8360 (mobile)
-

--

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: model design problem

2009-12-07 Thread Shawn Milochik
What kind of information will the database have to store about the ports 
themselves?

How will you need to be able to filter querysets by information in the port 
fields, if at all?

I'm going to throw this one solution out there, but depending on your needs it 
may not fit:

Create a red_ports column and a green_ports column in your model. Each one will 
contain serialized JSON. You can just dump a Python dictionary into those 
fields with simplejson.dumps, and retrieve the data with simplejson.loads. 
Then, you add methods to your model which you can use in the views that deal 
with the model.





Here are a couple of lines of code from one of my models. I'm storing the 
hashes of old passwords to prevent people from re-using passwords.

#field definition in model
prev_passwords = models.TextField(default = '{}')

I then get and set the values like this:

def _get_prev_passwords(self):
return simplejson.loads(self.prev_passwords)

def _set_prev_passwords(self, pw_dict):
self.prev_passwords = simplejson.dumps(pw_dict)

previous_passwords = property(_get_prev_passwords, _set_prev_passwords)

This way, my model's .previous_passwords attribute is available in my views, 
and the serialization is transparent.




So, your Python dictionaries can contain all kinds of data about the red and 
green ports, and contain entries for any number of ports. Your models remain 
clean.
The biggest flaw in this method is that, if you need to select a set of 
products based on an attribute of a port, you'll have to jump through hoops to 
make it happen.

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: Pydev + Django + Ubuntu 9.10

2009-12-07 Thread turkan
Hello Brian.

Strange, I am also using Eclipse downloaded from eclipse.org. Did you
add any special folders to the PYTHONPATH? Are you using django from
the Ubuntu repositories?

On Dec 7, 6:06 am, Brian McKeever  wrote:
> I was having the same trouble you are when I installed eclipse from
> the repository.
> I fixed it by downloading it again from the 
> websitehttp://www.eclipse.org/downloads/
> (Eclipse IDE for C/C++ Developers (79 MB) is the one I picked
> specifically).

--

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: browser input and strings

2009-12-07 Thread rvandam
I cut the model down too much this one is missing:

lijst = models.ForeignKey('Menu_nl')

this is the Menu_nl model:
class Menu_nl(models.Model):
categorie = models.CharField(max_length=50)
order = models.IntegerField()
slug = models.SlugField()
def __unicode__(self):
return self.slug
class Meta:
verbose_name_plural = "Menu_nl"

Rob

--

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 design problem

2009-12-07 Thread Dan
I am relatively new to django and relational databases, and need some
Model advice.

I have a family of network products each with a different combination
of ports.. I will call them red ports and green ports.  For example,
product A will have its own Model and could have 2 red ports and 1
green port.  Product B is similar, but has only 3 green ports.
My current approach is to use an abstract base Model, and then create
Models for products A and B that contain all needed fields, for
example:

class A(basemodel):
   Port1_redfield1 = ...
   Port1_redfield2 = ...
   ...
   Port2_redfield1 = ...
   Port2_redfield2 = ...
   ...


Yuck, not very DRY at all.  I also tried to create a red port Model
and green port Model and use one to one fields to connect them to
products.  The problem with this is that I could not figure out how to
encapsulate the ports; I always had to worry about creating, linking
and deleting port objects when dealing with products.  Not acceptable.

I also thought about other tricks like generating my models.py file
from a generator program, and dynamic insertion of attributes into
existing classes.  I really would rather not go there.

So, my question:  Is there a nice DRY way to get the kind of
structured composition that I want?

Side question: Is there another python ORM that could address my need
better?

Thanks,
Dan.

--

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: browser input and strings

2009-12-07 Thread rvandam
Hi Shawn thanks for your reply.

I have some categories, with multiple items per category. If a user
enters http://mysite.com/items-from-100-to-1000 I want a short
description of all items in that category listed.

I have done this so far with:
   {% for x in browse_lijst %}
 {% ifequal x.lijst.__str__ browse.__str__ %}
{{x.titel}}

etc. etc.

This works with Django 1.0 but gives problems when i try to upgrade.

Here is the model:
class Nl(models.Model):
publiceren = models.BooleanField()
titel = models.CharField(max_length=60)
tekst = models.TextField()
prijs = models.CharField(max_length=12)
slug = models.SlugField(max_length=60)
kort = models.TextField()
thumb = models.ImageField(upload_to='verkoop/thumb/%Y/%m/%d',
default='verkoop/thumb/geen_afbeelding.jpg', blank=True)
remove_thumb = models.BooleanField()
plaatje1 = models.ImageField(upload_to='verkoop/%Y/%m/%d',
blank=True)
remove_plaatje1 = models.BooleanField()
etc.etc.

Please let me know if you need more info

--

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 Flatpage Internationalization BUG

2009-12-07 Thread Carlos Ricardo Santos
So just put your http://localhost:PORT if you're in development, or the real
link if you are in production

:D


2009/12/7 Cyberbiagio 

> Thanks for your suggestion but in site there is mysite.com and the
> sites_id is correctly linked to flat page id
>
> :(
>
> On 7 Dic, 14:42, Carlos Ricardo Santos 
> wrote:
> > Check in the admin panel if you have linked it to a site, then check
> > settings.Py if the site_id matches the id of the site you associated in
> the
> > admin.
> >
> > On Dec 7, 2009 12:08 PM, "Cyberbiagio"  wrote:
> >
> > Hi,
> >
> > i'm a new django developer, i need help for a strange bug:
> >
> > I have a web sit in 2 languages: en, es
> > In this website the Internationalization system (i18n) works fine in
> > exception for the only flatpage that i have.
> > In fact when the user is on that web page (named "about-us") if he
> > change language with the language-flag, the page does not update
> > itself.
> > So i need (i think) to redirect the page by urls.py to flatpage.view
> > manually but i receive a strange url in my browser address bar:
> > "http://about-us//"; instead ofhttp://www.mysite.com/en-about-us/
> >
> > Here the code:
> >
> > Base.html (button link):
> >
> > 
> >
> > Urls.py:
> >
> > url(r'^(?P[a-zA-Z0-9-_]+)/
> > $','PROJECTNAME.APPNAME.views.translated_url',
> > {},name='flatpage_translate'),
> >
> > Views.py:
> >
> > from django.utils import translation
> > from django.contrib.flatpages.views import flatpage
> >
> > def translated_url(request,slug):
> >curr_lang = translation.get_language()
> >return flatpage(request,'/%s-%s'%(curr_lang,slug))
> >
> > I hope anyone can help me.
> >
> > Thank You very much!
> >
> > --
> >
> > 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 athttp://
> 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.
>
>
>


-- 
Cumprimentos,
Carlos Ricardo Santos

--

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 Flatpage Internationalization BUG

2009-12-07 Thread Cyberbiagio
Thanks for your suggestion but in site there is mysite.com and the
sites_id is correctly linked to flat page id

:(

On 7 Dic, 14:42, Carlos Ricardo Santos 
wrote:
> Check in the admin panel if you have linked it to a site, then check
> settings.Py if the site_id matches the id of the site you associated in the
> admin.
>
> On Dec 7, 2009 12:08 PM, "Cyberbiagio"  wrote:
>
> Hi,
>
> i'm a new django developer, i need help for a strange bug:
>
> I have a web sit in 2 languages: en, es
> In this website the Internationalization system (i18n) works fine in
> exception for the only flatpage that i have.
> In fact when the user is on that web page (named "about-us") if he
> change language with the language-flag, the page does not update
> itself.
> So i need (i think) to redirect the page by urls.py to flatpage.view
> manually but i receive a strange url in my browser address bar:
> "http://about-us//"; instead ofhttp://www.mysite.com/en-about-us/
>
> Here the code:
>
> Base.html (button link):
>
> 
>
> Urls.py:
>
> url(r'^(?P[a-zA-Z0-9-_]+)/
> $','PROJECTNAME.APPNAME.views.translated_url',
> {},name='flatpage_translate'),
>
> Views.py:
>
> from django.utils import translation
> from django.contrib.flatpages.views import flatpage
>
> def translated_url(request,slug):
>        curr_lang = translation.get_language()
>        return flatpage(request,'/%s-%s'%(curr_lang,slug))
>
> I hope anyone can help me.
>
> Thank You very much!
>
> --
>
> 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 groups.com>
> .
> For more options, visit this group 
> athttp://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.




how to allow RSS aggregators to use feeds available only for logged-in users?

2009-12-07 Thread Miernik
I want to have RSS feeds in my Django application, which should be
viewable only by a logged-in user. I want to allow users to add these
RSS feeds to all aggregators, so I would need something which would
work like this: supply the feed URL with a token, for example:
http://example.com/feed/rss&token=AeYQtFjQfjU5m  so that token will
cause the feed to be seen as if the user would be logged in.

Is there some library in Django which would provide such a
functionality?

--

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: browser input and strings

2009-12-07 Thread Shawn Milochik
What exactly are you trying to do? Can you give a little of the data in your 
model, and then exactly how you want it to look on the rendered page? I'm 
having some trouble understanding what your template and view are intended to 
do.

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: Model instances used for class attributes

2009-12-07 Thread Thomas Guettler


bruno desthuilliers wrote:
> On 7 déc, 11:45, Thomas Guettler  wrote:
>> Hi,
>>
>> I have this code:
>>
>> from django.contrib.auth.models import Group
>>
>> class MyModel(models.Model):
>> default_group=Group.objects.get(name='MyGroup')
>>
>> This worked, since I added the Model after the group MyGroup
>> was created. But it breaks syncdb.
> 
> Indeed.
> 
>> I need this on the class, using a property does not work, since
>> AFAIK properties only work for instances.
> 
> The property builtin type only "works" for instances, yes, but well,
> the property type is just one possible application of the descriptor
> protocol - 

thank you for this hint. The descriptor __get__() is what I use now.

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--

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 i find out that Development server is running or not?

2009-12-07 Thread Tim Chase
> how can i find out that my project ran under apache or development server ?

Though not 100% foolproof, I usually use

   from sys import argv
   if 'runserver' in argv:
 do_development_server_stuff()
   else:
 do_non_development_server_stuff()

-tim



--

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 Flatpage Internationalization BUG

2009-12-07 Thread Carlos Ricardo Santos
Check in the admin panel if you have linked it to a site, then check
settings.Py if the site_id matches the id of the site you associated in the
admin.

On Dec 7, 2009 12:08 PM, "Cyberbiagio"  wrote:

Hi,

i'm a new django developer, i need help for a strange bug:

I have a web sit in 2 languages: en, es
In this website the Internationalization system (i18n) works fine in
exception for the only flatpage that i have.
In fact when the user is on that web page (named "about-us") if he
change language with the language-flag, the page does not update
itself.
So i need (i think) to redirect the page by urls.py to flatpage.view
manually but i receive a strange url in my browser address bar:
"http://about-us//"; instead of http://www.mysite.com/en-about-us/

Here the code:

Base.html (button link):



Urls.py:

url(r'^(?P[a-zA-Z0-9-_]+)/
$','PROJECTNAME.APPNAME.views.translated_url',
{},name='flatpage_translate'),

Views.py:

from django.utils import translation
from django.contrib.flatpages.views import flatpage

def translated_url(request,slug):
   curr_lang = translation.get_language()
   return flatpage(request,'/%s-%s'%(curr_lang,slug))


I hope anyone can help me.

Thank You very much!

--

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.




browser input and strings

2009-12-07 Thread rvandam
I have an application that generates a list of items in a category.
Therefore i have this in my urls.py:

 (r'^categorie/(.*)/$', browse_page),

This is my view..py:

def browse_page(request, browse):
browse_lijst = Nl.objects.all()
menu = Menu_nl.objects.all().order_by('order')
return render_to_response('p_verkoop_categorie.htm', {
'browse_lijst': browse_lijst,
'menu': menu,
}, context_instance = RequestContext(request))

I have this in my template (i know this is ugly):
 {% ifequal x.lijst.__str__ browse.__str__ %}

I tried to remove the above from the template and replace this with
this in my view:
def browse_page(request, browse):
menu = get_list_or_404(Menu_nl, slug=browse)
browse_lijst = Nl.objects.filter(lijst=browse)
return render_to_response('p_verkoop_categorie.htm', {
'browse_lijst': browse_lijst,
  'menu': menu,
}, context_instance = RequestContext(request))

This leads to a template error:
Caught an exception while rendering: Incorrect integer value:

How and where should i convert the browser input into a string?

--

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: Unique model field and case sensitivity (postgres)

2009-12-07 Thread David De La Harpe Golden
chefsmart wrote:
> By the way, right now I'm using a State.objects.get(name__iexact=name)
> in clean_name() method in a form subclass to prevent creation of case-
> insensitive duplicates. Just wondering if there is a built-in or
> better way.
>

Well, in postgresql itself one can make a case insensitive unique
constraint using "functional index" functionality:

create unique index app_state_lower_name_idx on app_state(lower(name));

as per: http://archives.postgresql.org/pgsql-general/2005-09/msg00842.php


I guess django's ORM would need some surgery to make it automagically
generate and manage such constraints though.


--

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: Model instances used for class attributes

2009-12-07 Thread bruno desthuilliers
On 7 déc, 11:45, Thomas Guettler  wrote:
> Hi,
>
> I have this code:
>
> from django.contrib.auth.models import Group
>
> class MyModel(models.Model):
>     default_group=Group.objects.get(name='MyGroup')
>
> This worked, since I added the Model after the group MyGroup
> was created. But it breaks syncdb.

Indeed.

> I need this on the class, using a property does not work, since
> AFAIK properties only work for instances.

The property builtin type only "works" for instances, yes, but well,
the property type is just one possible application of the descriptor
protocol - FWIW, the function type implements the descriptor protocol
too (that's how functions become methods), and Django's models
relationships are also implemented using custom descriptors. Oh, and
yes : a descriptor's __get__ method is always called, whether it's
looked up on a class or instance (else classmethods or unboundmethods
wouldn't work). So one possible solution could be to write your own
custom descriptor:

class DefaultModelAttribute(object):
def __init__(self, lookup_method, **lookup_args):
self._lookup_method = lookup_method
self._lookup_args = lookup_args
def __get__(self, instance, cls=None):
return self._lookup_method(**self._lookup_args)
def __set__(self, instance, value):
raise AttributeError("read-only, sorry")


class MyModel(models.Model):
default_group=DefaultModelAttribute(Group.objects.get,
name='MyGroup')

NB : untested code, so according to Murphy's law it should of course
break on first test with a very obvious (or very obscure...) error !-)


Now I'm not sure it's the right thing to do - depending on how you
expect this to be used, it may or not work correctly, and even then it
might as well be pure overkill. So if may ask: do you really need to
have a computed attribute here ? How do you use this attribute
exactly ?


--

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 apps do besides provide views?

2009-12-07 Thread bruno desthuilliers


On 5 déc, 16:34, Preston Holmes  wrote:
> On Dec 3, 12:02 pm, Wayne Koorts  wrote:
(snip)
> > Can anyone point out a section in the docs (or anywhere else actually)
> > the Django "app" concept?  I've had a look through the docs but
> > haven't been able to find anything specifically about that.
>
> This is not very well documented in official docs, and is really a bit
> amorphous.
>
> I like to think of an app is to Django as a Class is to Python.

s/class/package/

A django app is a Python package which usually respects a couple
'layaout' conventions and is meant to be used in a Django project.
What it provides is up to the author.

--

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: Extending result count at bottom of admin pages

2009-12-07 Thread Count László de Almásy
On Dec 6, 9:33 am, Kaze  wrote:
> You can override "changelist_view" function in admin.py for that
> model.

ok, thanks, that helped me figure out a solution. here's what i added
to admin.py within my Sales class. i can then access 'cl.amount_sum'
from my pagination.html template. anything wrong with how i did this?
i'll admit i don't fully understand all that is happening here.

==

def changelist_view(self, request, extra_context=None, **kwargs):
from django.contrib.admin.views.main import ChangeList
cl = ChangeList(request, self.model, list(self.list_display),
self.list_display_links, self.list_filter,
self.date_hierarchy, self.search_fields,
self.list_select_related,
self.list_per_page,
self.list_editable,
self)
cl.formset = None
q = cl.query_set.extra(select={'amount_sum': 'SUM(amount)'})
cl.amount_sum = q.all()[0].amount_sum

if extra_context is None:
extra_context = {}

extra_context['cl'] = cl
return super(SalesAdmin, self).changelist_view(request,
extra_context=extra_context)

==

--

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: admin templates issue

2009-12-07 Thread gentlestone
Sorry, my stupid mystake. I've copied bat templates from old Django
1.0 version.

On 7. Dec., 08:50 h., gentlestone  wrote:
> I did not make any changes, just copied the original template to
> template/admin
>
> I tried to copy the tepmplate to root (templates/admin) for every app
> and model
>
> and also I tried copy the template to some app and model - the same
> result
>
> Because it didn't work, I put the line:
>
> 
>
> into base.html. After this (bug?) fixing everything works fine. But
> the bad feeling remains. Here is a beginning of base.html after my
> correction
>
>  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
> http://www.w3.org/1999/xhtml"; lang="{{ LANGUAGE_CODE }}"
> xml:lang="{{ LANGUAGE_CODE }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif
> %}>
> 
> {% block title %}{% endblock %}
> 
> 
> {% if LANGUAGE_BIDI %}{% endif %}
>
> On 5. Dec., 05:21 h., Sam Lai  wrote:
>
> > 2009/12/4gentlestone:
>
> > > I've tried to folow the tutorial and customize the admin template and
> > > made a copy of 'change_form.html' template into the 'templates/admin'
> > > directory in my project. I also set the
> > > TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__),
> > > 'templates').replace('\\','/'),
>
> > > After this, the result is BAD. In the result admin page source code,
> > > the line
>
> > > 
>
> > > is missing. I recognized the change_form.html rewrites the stylesheet
> > > block:
>
> > > {% block stylesheet %}{% admin_media_prefix %}css/forms.css{% endblock
> > > %}
>
> > > so I know why, but the original non-copy version of change_form.html
> > > is the SAME! How can it works in the original? I am totally confused.
>
> > > What am I doing wrong? Some setting is missing?
>
> > Are you trying to override the admin template for every app and model?
> > Or only for a specific app or model?
>
> > What changes have you made in your own templates/admin/change_form.html?

--

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 instances used for class attributes

2009-12-07 Thread Thomas Guettler
Hi,

I have this code:

from django.contrib.auth.models import Group

class MyModel(models.Model):
default_group=Group.objects.get(name='MyGroup')

This worked, since I added the Model after the group MyGroup
was created. But it breaks syncdb.

I need this on the class, using a property does not work, since
AFAIK properties only work for instances.

Has someone a solution?

  Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

--

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 i find out that Development server is running or not?

2009-12-07 Thread Sameer Rahmani
hi
how can i find out that my project ran under apache or development server ?

--

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: Hello

2009-12-07 Thread Waqqas Jabbar
you can go in admin site and add/modify/remove user and user permissions

On Mon, Dec 7, 2009 at 11:13 AM, Tsolmon Narantsogt wrote:

> How to use a permission.
> ./manage.py  syncdb
> then  how to create a users permissions
>
> --
>
> 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.




Custom get/set from model

2009-12-07 Thread Waqqas Jabbar
Peace to all,

I want to do a custom implementation of "get" and "set" functions of a
database model. Do I ve to write a custom model manager or derive a class
from models.Model ?
Is it possible to write custom "get" and "set" functions for a model field ?

goto

--

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: Pydev + Django + Ubuntu 9.10

2009-12-07 Thread Info Cascade
Hi, Turkan,

Sorry -- the link is: here.  
Hope
that helps.
I had to use Postgres 8.3 instead of 8.4, but that may not be an issue
if you're not using PostGIS.

Liam



turkan wrote:
> Hello Liam,
>
> I am sorry ... I can't access your provided link. Even after
> registering there, it says "You are not authorized to view this
> workspace.".
> I am also not sure why you suggest me Posgresql/PostGIS. I don't have
> any problems with setting up the database, just with setting up Pydev/
> Eclipse correctly.
> Any further suggestions?
>
> Regards,
> Kai
>
>
> On Dec 6, 12:08 am, Info Cascade  wrote:
>   
>> Turkan,
>>
>> Perhaps this will help. I just have done this
>> (PostGIS/Eclipse/Pydev/Django on Ubuntu 9.10) and it's working great!
>> After having problems because I had installed Postgres 8.4, I found the
>> script below, on the net somewhere.
>> Modify, as appropriate, if you don't need GIS.
>>
>> You may also want this, for full support in pgadmin3:
>> apt-get install postgresql-contrib-8.3
>> cd /usr/share/postgresql/8.3/contrib
>> psql -U  postgres < adminpack.sql
>>
>> Getting Eclipse working took some time, and I learned a lot from 
>> this:http://www.socialtext.net/hearplanet/index.cgi?action=display;is_inci...
>>
>> Best,
>> Liam
>>
>> 
>>> # Script for installing Django, PostgreSQL, and PostGIS
>>> # Run with sudo
>>>   
>>> # Install Django:
>>> apt-get install python-django python-django-doc
>>>   
>>> # Install PostgreSQL 8.3
>>> apt-get install postgresql-8.3 python-psycopg2 pgadmin3
>>>   
>>> # Packages needed by GeoDjango (gdal is optional, but useful)
>>> apt-get install postgresql-8.3-postgis binutils libgdal1-1.5.0
>>> gdal-bin libgeos-3.1.0 proj libpq-dev
>>>   
>>> # Set yourself up as a PostgreSQL superuser
>>> su - postgres
>>> createuser --createdb --superuser `whoami`
>>>   
>>> # Create the template spatial database
>>> createdb -E UTF8 template_postgis
>>> createlang -d template_postgis plpgsql # Adding PLPGSQL language support.
>>>   
>>> # Allows non-superusers the ability to create from this template
>>> psql -d postgres -c "UPDATE pg_database SET datistemplate='true' WHERE
>>> datname='template_postgis';"
>>>   
>>> # Load the PostGIS SQL routines
>>> psql -d template_postgis -f
>>> /usr/share/postgresql-8.3-postgis/lwpostgis.sql
>>> psql -d template_postgis -f
>>> /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql
>>>   
>>> # Enable users to alter spatial tables
>>> psql -d template_postgis -c "GRANT ALL ON geometry_columns TO PUBLIC;"
>>> psql -d template_postgis -c "GRANT ALL ON spatial_ref_sys TO PUBLIC;"
>>> exit
>>>   
>> turkan wrote:
>> 
>>> Hello.
>>>   
>>> I know ... this topic was discussed quite often. But all the hints I
>>> found don't really help to setup Eclipse/Pydev under Ubuntu 9.10 for
>>> Django 1.1 (from the official Ubuntu repositories).
>>> I tried to follow this tutorial (http://solyaris.wordpress.com/
>>> 2007/05/16/how-to-djangopydev-on-feisty/), but /usr/share/python-
>>> support/python-django/ is not present anymore under Ubuntu 9.10.
>>> So I tried to add /usr/shared/pyshared/django, usr/share/python-
>>> support/, /usr/lib/python/django to the PYTHONPATH, but without any
>>> success. My projects still come up with many "undefined variable"
>>> errors. For example an error is presented for User.add_to_class.
>>> add_to_class (add_to_class is unkown), even if User seems to be known.
>>> I read that it is difficult for the IDE to recognize all variables,
>>> cause of the way some of those are generated on the fly (I am also new
>>> to Python). But is it possible to get error free projects with Django
>>> + Pydev?
>>> Why does Aptana for example does provide such a good Ruby support?
>>> Does Python/Django provide more dynamic stuff than Ruby?
>>>   
>>> Regards,
>>> Kai
>>>   
>>> --
>>>   
>>> 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 
>>> athttp://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.
>
>
>
>   

--

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