Foreign Key problems with legacy database

2013-07-22 Thread Brian Millham
I have the following models:

class Requestlist(models.Model):
>id = models.IntegerField(primary_key=True)
>songid = models.Integerfield()
>song = ForeignKey('Song', db_column='songid')
> class Song(models.Model):
>   id = models.IntegerField(primary_key=True)
>   title = models.CharField(max_length=255L)


The relation should be Requestlist.songid = Song.id

The above models seem to work for querying, but when I create a new 
requestlist, via a form, then I get the error that: Column songid specified 
twice.

If I remove the ForeignKey, I can save the requestlist, but obviously I 
lose the relations.

I've tried replacing the db_column='songid' with to_field='id' but that's 
worse. The relation then totally breaks. 

It's gotta be something simple that I'm overlooking

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Foreign key problems with legacy database

2013-07-22 Thread Brian Millham
I have these 2 models:

class Requestlist(model.Model):

 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




python manage.py runserver error

2013-07-22 Thread Jay Lozier
I get the following error when run python manage.py runserver:

OS openSUSE 12.3
django 1.7


boopers@linux-nss6:~/myfirstsite> python manage.py runserver
Traceback (most recent call last):
File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
File "/home/boopers/django-trunk/django/core/management/__init__.py", line 
397, in execute_from_command_line
utility.execute()
File "/home/boopers/django-trunk/django/core/management/__init__.py", line 
390, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/boopers/django-trunk/django/core/management/__init__.py", line 
261, in fetch_command
app_name = get_commands()[subcommand]
File "/home/boopers/django-trunk/django/core/management/__init__.py", line 
107, in get_commands
apps = settings.INSTALLED_APPS
File "/home/boopers/django-trunk/django/conf/__init__.py", line 54, in 
__getattr__
self._setup(name)
File "/home/boopers/django-trunk/django/conf/__init__.py", line 50, in 
_setup
self._configure_logging()
File "/home/boopers/django-trunk/django/conf/__init__.py", line 68, in 
_configure_logging
from django.utils.log import DEFAULT_LOGGING
File "/home/boopers/django-trunk/django/utils/log.py", line 7, in 
from django.views.debug import ExceptionReporter, 
get_exception_reporter_filter
File "/home/boopers/django-trunk/django/views/debug.py", line 10, in 

from django.http import (HttpResponse, HttpResponseServerError,
File "/home/boopers/django-trunk/django/http/__init__.py", line 4, in 

from django.http.response import (HttpResponse, StreamingHttpResponse,
File "/home/boopers/django-trunk/django/http/response.py", line 16, in 

from django.utils import six, timezone
File "/home/boopers/django-trunk/django/utils/timezone.py", line 11, in 

import pytz
File "/usr/lib/python2.7/site-packages/pytz/__init__.py", line 35, in 

from pkg_resources import resource_stream
File 
"/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", 
line 3027, in 
add_activation_listener(lambda dist: dist.activate())
File 
"/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", 
line 741, in subscribe
callback(dist)
File 
"/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", 
line 3027, in 
add_activation_listener(lambda dist: dist.activate())
File 
"/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", 
line 2514, in activate
list(map(declare_namespace, self._get_metadata('namespace_packages.txt')))
File 
"/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", 
line 2094, in declare_namespace
_handle_ns(packageName, path_item)
File 
"/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg/pkg_resources.py", 
line 2059, in _handle_ns
raise TypeError("Not a package:", packageName)
TypeError: ('Not a package:', 'cgi')


The sys paths are

/usr/lib/python2.7/site-packages/pymongo-2.5.1-py2.7-linux-x86_64.egg
/usr/lib/python2.7/site-packages/bottle-0.11.6-py2.7.egg
/usr/lib/python2.7/site-packages/translationstring-1.1-py2.7.egg
/usr/lib/python2.7/site-packages/venusian-1.0a8-py2.7.egg
/usr/lib/python2.7/site-packages/zope.deprecation-4.0.2-py2.7.egg
/usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg
/home/boopers/django-trunk
/usr/lib/python27.zip
/usr/lib64/python2.7
/usr/lib64/python2.7/plat-linux2
/usr/lib64/python2.7/lib-tk
/usr/lib64/python2.7/lib-old
/usr/lib64/python2.7/lib-dynload
/usr/lib64/python2.7/site-packages
/usr/lib64/python2.7/site-packages/FontTools
/usr/lib64/python2.7/site-packages/PIL
/usr/local/lib64/python2.7/site-packages
/usr/local/lib/python2.7/site-packages
/usr/lib64/python2.7/site-packages/gst-0.10
/usr/lib64/python2.7/site-packages/gtk-2.0
/usr/lib64/python2.7/site-packages/input-pad-1.0
/usr/lib/python2.7/site-packages
/usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re:

2013-07-22 Thread Harjot Mann
On Tue, Jul 23, 2013 at 3:55 AM, Nikolas Stevenson-Molnar
 wrote:
> Ok. So if I understand correctly, your request should be to /myview/ not to
> /report/myview/


No, the problem was not with urls. It was having a link with the css
file, which does not exist. Now it is resolved.
THanks everyone for ur help. :)

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: python manage.py runserver error

2013-07-22 Thread Christian Erhardt
I think you're missing some prerequisites (TypeError: ('Not a package:', 
'cgi')) 

I never use the libraries installed on the system, i always work with 
virtualenvs. A very good kickstart is written down here: 
http://www.jeffknupp.com/blog/2012/02/09/starting-a-django-project-the-right-way/

Usually i start everything from a pinax project so i'm not sure if django 
has a requirements.txt. But if it has and you have activated your 
virtualenv (. venv/bin/activate), alle requisites can installed, simply by 
executeing the following command:

pip install -r requirements.txt 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Saving data from a form.

2013-07-22 Thread Nigel Legg
models.py:
class DataTable(models.Model):
datFile = models.CharField(max_length = 200)
structFile = models.CharField(max_length = 200)
bannerVar = models.CharField(max_length = 50)
stubVar = models.CharField(max_length = 50)
stubNets = models.BooleanField()

def __unicode__(self):
return u'%s %s %s %s' % (self.datFile, self.structFile,
self.bannerVar, self.stubVar)

forms.py:
class DataTableForm(forms.ModelForm):
class Meta:
model = DataTable

views.py:
def datatables(request):
if request.method == 'POST':
form = DataTableForm(request.POST)
if form.is_valid():
form.save()
DataTable_id = DataTable.id
return render(request, 'myapp/tabspec/{{DataTable_id}}.html', {
'DataTable_id' : DataTable.id,
})
else:
form = DataTableForm()
return render(request, 'myapp/datatables.html', {
'form': form,
})


When I input data on the form, and click "Confirm Selections", I get
"object DataTable has no attribute 'DataTable_id'"
Should I be using a different method to save the data from the form to the
database?


Regards,
Nigel Legg
07914 740972
http://www.trevanianlegg.co.uk
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re:

2013-07-22 Thread Nikolas Stevenson-Molnar
Ok. So if I understand correctly, your request should be to /myview/
/not /to /report/myview/

_Nik

On 7/22/2013 12:32 PM, Harjot Mann wrote:
> On Mon, Jul 22, 2013 at 10:22 PM, Nikolas Stevenson-Molnar
>  wrote:
>> Is that your only URLs file, or is there another one which includes that
>> one?
>
> Its the url's file which contains the urls of pdf.py file.
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




URL code not getting resolved in Part 4 of Tutorial

2013-07-22 Thread David Jenkins
After switching to "generic views", the link on my "polls" index page looks 
like this:

What's up?

Before I switched to the generic views code, all was working fine. To do 
the swithc, I simply cut and pasted the code from the Part 4 page to my 
pages (polls/urls.py and  polls/views.py,according to 
https://docs.djangoproject.com/en/1.5/intro/tutorial04/).  Now, of course, 
when I click on the link, I get an error.

Any suggestions would be much appreciated.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




How to set the email to lowercase on User Creation?

2013-07-22 Thread Cody Scott
I have a custom auth app. I am trying to only allow emails to be lower case 
in the database.
I can create a user in the admin with Capitalized letters, even with 
email.lower() in the create_user method.

Another solution would be to specify to the authenticate that the email can 
be any case.

user = authenticate(email=email, password=password)

#models.py

class MyUserManager(BaseUserManager):
def create_user(self, username, name, email, company, password, is_manager):
#if not username:
#raise ValueError('User must have a username')

user = self.model(username=username,
email=MyUserManager.normalize_email(email.lower()),
#email=email.lower(),
name=name, company=company, is_manager=is_manager
)

user.set_password(password)
user.save(using=self._db)

#checks pending teams in the login view
return user

def create_superuser(self, password, username='', email=''):
user = self.create_user(username=username,
name='',
email=email,
company='not_a_companyNAMe',
password=password,
is_manager=False
)
user.is_admin = True
user.is_superuser = True
user.save(using=self._db)
return user

class Users(AbstractBaseUser, PermissionsMixin):
email   = models.EmailField(verbose_name=_('email address'), 
max_length=255, blank=True, unique=True)
name= models.CharField(verbose_name=_('Name'), max_length=50, 
blank=True)
company = models.CharField(verbose_name=_('Company'), 
max_length=255, blank=True)
is_manager  = models.BooleanField(default=False, verbose_name=_('Check 
this box if you are a manager or need to create teams'))
is_active   = models.BooleanField(default=True)
is_admin= models.BooleanField(default=False)
is_customer = models.BooleanField(default=False)
datecreated = models.DateField(auto_now=True)

objects = MyUserManager()
if settings.LDAP:
username= models.CharField(verbose_name=_('Username'), 
max_length=50, unique=True)
USERNAME_FIELD  = 'username'
else:
username= models.CharField(verbose_name=_('Username'), 
max_length=50)
USERNAME_FIELD  = 'email'

REQUIRED_FIELDS = []

class Meta:
verbose_name_plural = "Users"


#admin.py

class UserCreationForm(forms.ModelForm):

password1 = forms.CharField(label='Password', widget=forms.PasswordInput)
password2 = forms.CharField(label='Password confirmation', 
widget=forms.PasswordInput)
name  = forms.CharField(label='Name', widget=forms.TextInput)
company   = forms.CharField(label='Company', widget=forms.TextInput)
is_manager= forms.BooleanField(label='Manager', required=False)

class Meta:
model = Users

def clean_password2(self):
# Check that the two password entries match
password1 = self.cleaned_data.get("password1")
password2 = self.cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
raise forms.ValidationError("Passwords don't match")
return password2

def save(self, commit=True):
# Save the provided password in hashed format
user = super(UserCreationForm, self).save(commit=False)
user.set_password(self.cleaned_data["password1"])
user.name = self.cleaned_data["name"]
user.company = self.cleaned_data["company"]
user.is_manager = self.cleaned_data['is_manager']
if commit:
user.save()
return user

class UserChangeForm(forms.ModelForm):
password = ReadOnlyPasswordHashField()

class Meta:
model = Users

def clean_password(self):
return self.initial["password"]

class MyUserAdmin(UserAdmin):
form = UserChangeForm
add_form = UserCreationForm

readonly_fields = ('last_login',)

list_display = ('name', 'email', 'is_manager', 'company',)
list_editable = ('email', 'is_manager', 'company',)
list_filter = ('is_admin',)
fieldsets = (
(None, {'fields': ('username', 'email', 'name', 'company', 
'password')}),
('Permissions', {'fields': ('is_manager', 'is_admin', 'groups', 
'user_permissions')}),
('Important dates', {'fields': ('last_login',)}),
)
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('email', 'name', 'company', 'password1', 'password2', 
'is_manager')}
),
)
search_fields = ('email', 'name', 'company', 'username',)
ordering = ('email',)
filter_horizontal = ()
admin.site.register(Users, MyUserAdmin)




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: Can I only have one "get_queryset" per Viewpage?

2013-07-22 Thread Pepsodent Cola
I'm having difficulty understanding the abstract explanations in that 
documentation.
Could you or somebody else explain this, by showing by example using my 
code examples?

*views.py*

class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = *'latest_poll_list'*

def get_queryset(self):
"""
Return the last five published polls
(not including those set to be published in the future).
"""
return Word.objects.filter(
pub_date__lte=timezone.now()
).order_by('-pub_date')[:5]

*### Filter 2*
#Word.objects.filter(translation='')
*### Filter 3*
#Pronunciation.objects.filter(wordfield__translation='')




*index.html*

index.html

{% if latest_poll_list %}

{% for word in *latest_poll_list* %}
{{ word.wordfield 
}}
{% endfor %}

{% else %}
No polls are available.
{% endif %}



How should I write my IndexView class so that Filter 1, 2 and 3 list 
results are then sent to my index.html template file?




On Monday, July 22, 2013 2:03:59 PM UTC+2, macndesign wrote:
>
> Hi, you can separate your querysets in get_context_data method.
> See: 
> https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data
>
>
> 2013/7/22 Pepsodent Cola 
>
>> Hi,
>>
>> Can I only have one "get_queryset" for each Viewpage?
>> If I wanted to add another database list on the same Viewpage how would 
>> that code look like for my Django *views.py* file?
>>
>> Example:
>> https://docs.djangoproject.com/en/1.5/intro/tutorial04/#amend-views
>>
>> from polls.models import Choice, Poll
>>
>> class IndexView(generic.ListView):
>> template_name = 'polls/index.html'
>> *context_object_name = 'latest_poll_list'*
>>
>> *def get_queryset(self):*
>> """Return the last five published polls."""
>> return Poll.objects.order_by('-pub_date')[:5]
>>
>>
>>
>> I mean will "context_object_name" be able to separate between several 
>> "get_queryset(self)"?
>> Because I want to have several different poll_lists on the same Viewpage.
>>
>> context_object_name = 'latest_poll_list'
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Att. *Mário Araújo Chaves Neto*
> *Programmer, Designer and U.I. Engineer*
> *
> *
> *MBA in Design Digital* - 2008 - FIC
> *Analysis and Systems Development* - 2011 - Estácio
> *D**esign and Implementation of Internet Environments* - 2003 - FIC
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to Create an Auto Incrementing Integer Field

2013-07-22 Thread Cody Scott
Thank you very much, that was exactly what I was looking for.

On Monday, 22 July 2013 09:48:51 UTC-4, Christian Erhardt wrote:
>
> Have a look at this post: 
> http://stackoverflow.com/questions/3123796/how-to-make-an-auto-filled-and-auto-incrementing-field-in-django-admin
>  
> They determine the next value by calling a function called number(). In 
> your case it would look something like this:
>
> class Cliente(models.Model):
>> """This is the client data model, it holds all client information. 
>> This
>>docstring has to be improved."""
>> def number():
>> no = Cliente.objects.all().aggregate(Max(order))
>> if no == None:
>> return 1
>> else:
>> return no + 1
>>
>> clientcode = models.IntegerField(_('Code'), max_length=6, 
>> unique=True, \
>> default=number)
>>
>  
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: (Noob) - filtering spanning relationship not working

2013-07-22 Thread Christian Erhardt
Calling count() on a queryset will always aggregate the count of all rows. 
Please have a look at the annotate function in the documentation 
https://docs.djangoproject.com/en/dev/topics/db/aggregation/ Annotate will 
group your results and sum up the results. 

I think what you'll have to do is:

assignment.finished_articles = Article.objects.filter(cowcode=country, 
pubdate__range(start_date, end_date), 
articlehistory__coder=request.user.id).annotate(number_of_articlehistory_entries=Count(articlehistory__id))

This should give you a list of Articles with an extra column 
'number_of_articlehistory_entries' with the count of articlehistory entries 
per article. I'm pretty sure, that in this list all articles are shown, 
even those with 0 articlehistory entries.
If you only want those with more than 1 articlehistory entries, you should 
start the query from the articlehistory class.

assignment.finished_articles = 
ArticleHistory.objects.filter(article__cowcode=country, 
article__pubdate__range(start_date, end_date), 
coder=request.user.id).annotate(number_of_articlehistory_entries=Count(id))

A count on assignment.finished_articles should return the number of 
articles that have at least 1 connected articlehistory entry.

Hope this helps

Am Montag, 22. Juli 2013 09:51:14 UTC+2 schrieb Lukas Kawerau:
>
> I want to find the number of articles for which a specific user has 
> created articlehistoryrecords.
> The models for that look like this:
>
> class Article(models.Model):
> """The basic entity of this app.)"""
> documentID = models.CharField(blank=True, max_length=1000)
> cowcode = models.IntegerField(blank=True, null=True)
> pubdate = models.DateField(default=datetime.datetime.today)
> headline = models.CharField(blank=True, max_length=1500)
> source = models.CharField(blank=True, max_length=5000)
> text = models.TextField(blank=True, max_length=100)
> assignments = models.ManyToManyField(Assignment)
>
> class Meta:
> ordering = ['pubdate']
>
> def __unicode__(self):
> return self.headline
> class ArticleHistory(models.Model):
> """(Modelname description)"""
> article = models.ForeignKey(Article, related_name='Article History')
> coder = models.ForeignKey(User, related_name='Article History')
> last_updated = models.DateTimeField(default=datetime.datetime.now)
>
> def __unicode__(self):
> return self.last_updated
>
> The way I'm trying to do this at the moment is like this:
>
> assignment.finished_articles = 
> Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date),
>  articlehistory__coder=request.user.id).count()
>
> This doesn't work, however and exhibits another weird behaviour:
> I try to do this:
>
> for assignment in assignments:
> country = assignment.country.cowcode
> start_date = assignment.start_date
> end_date = assignment.end_date
> articles = 
> Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date)).select_related()
> assignment.article_num = articles.count()
> #assignment.finished_articles = 
> Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date),
>  articlehistory__coder=request.user.id).count()
>
> This works fine, unless I try to include finished_articles, then 
> article_num gets shortened to one result.
>
> It would be really great if anyone has a pointer to who to solve this.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re:

2013-07-22 Thread Harjot Mann
On Mon, Jul 22, 2013 at 10:22 PM, Nikolas Stevenson-Molnar
 wrote:
> Is that your only URLs file, or is there another one which includes that
> one?


Its the url's file which contains the urls of pdf.py file.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Saving data from a form.

2013-07-22 Thread Nigel Legg
Thanks Christian. I'll get my head around this soon, I hope.

Regards,
Nigel Legg
07914 740972
http://www.trevanianlegg.co.uk
http://twitter.com/nigellegg
http://uk.linkedin.com/in/nigellegg



On 22 July 2013 14:53, Christian Erhardt wrote:

> The error lies in this two rows:
>
> form.save()
> DataTable_id = DataTable.id
>
> DataTable is the class, not the instance of the saved object! form.save()
> returns an instance of what has been saved. So your code should look like
> this:
>
> my_new_datatable_instance = form.save()
> DataTable_id = my_new_datatable_instance.id
>
> That should do the trick
>
>
> Am Montag, 22. Juli 2013 13:02:46 UTC+2 schrieb Nigel Legg:
>
>> models.py:
>> class DataTable(models.Model):
>> datFile = models.CharField(max_length = 200)
>> structFile = models.CharField(max_length = 200)
>> bannerVar = models.CharField(max_length = 50)
>> stubVar = models.CharField(max_length = 50)
>> stubNets = models.BooleanField()
>>
>> def __unicode__(self):
>> return u'%s %s %s %s' % (self.datFile, self.structFile,
>> self.bannerVar, self.stubVar)
>>
>> forms.py:
>> class DataTableForm(forms.ModelForm)**:
>> class Meta:
>> model = DataTable
>>
>> views.py:
>> def datatables(request):
>> if request.method == 'POST':
>> form = DataTableForm(request.POST)
>> if form.is_valid():
>> form.save()
>> DataTable_id = DataTable.id
>> return render(request, 'myapp/tabspec/{{DataTable_id}**}.html',
>> {
>> 'DataTable_id' : DataTable.id,
>> })
>> else:
>> form = DataTableForm()
>> return render(request, 'myapp/datatables.html', {
>> 'form': form,
>> })
>>
>>
>> When I input data on the form, and click "Confirm Selections", I get
>> "object DataTable has no attribute 'DataTable_id'"
>> Should I be using a different method to save the data from the form to
>> the database?
>>
>>
>> Regards,
>> Nigel Legg
>> 07914 740972
>> http://www.trevanianlegg.co.uk
>> http://twitter.com/nigellegg
>> http://uk.linkedin.com/in/**nigellegg
>>
>>   --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: dear someone,

2013-07-22 Thread Brian Schott
NAME (path to a database file) should include the filename, not just a 
directory.  Try './mysite/mysite.db' for NAME.

Brian

On Jul 22, 2013, at 1:44 PM, Stian Sjøli  wrote:

> I am trying to start up with django using the tutorial on the website. I get 
> the following error "OperationalError: unable to open database file. I have 
> change the mood for all my files so that everybody (user, group and others 
> have all right to all the files in the folder). My settings.py file I have 
> modified to say(so that I can use the builtin sqlite3 with python;
> 
> DATABASES = {
> 'default': {
> 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 
> 'mysql', 'sqlite3' or 'oracle'.
> 'NAME': './mysite/',  # Or path to database file 
> if using sqlite3.
> # The following settings are not used with sqlite3:
> 'USER': '',
> 'PASSWORD': '',
> 'HOST': '',  # Empty for localhost through domain 
> sockets or '127.0.0.1' for localhost through TCP.
> 'PORT': '',  # Set to empty string for default.
> }
> }
> 
> from another tutorial I wonder if it could be that django does not know of 
> where my python is, and vica versa...
> 
> i am greatful for any help or suggestions.
> 
> 
> stian
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




OperationalError: unable to open database file

2013-07-22 Thread Stian Sjøli
i get this error while going throught the tutorial from the django website. 
I am a mac user, and have modified my settings-file to use sqlite3 and the 
name variable to say "./mysite". Any suggestions why I get this error?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




dear someone,

2013-07-22 Thread Stian Sjøli
I am trying to start up with django using the tutorial on the website. I 
get the following error "OperationalError: unable to open database file. I 
have change the mood for all my files so that everybody (user, group and 
others have all right to all the files in the folder). My settings.py file 
I have modified to say(so that I can use the builtin sqlite3 with python;

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 
'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': './mysite/',  # Or path to database 
file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '',  # Empty for localhost through 
domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '',  # Set to empty string for default.
}
}

from another tutorial I wonder if it could be that django does not know of 
where my python is, and vica versa...

i am greatful for any help or suggestions.


stian

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: new field in models

2013-07-22 Thread Harjot Mann
On Mon, Jul 22, 2013 at 2:33 PM, Satinderpal Singh
 wrote:
> South is an alternative, it creates table fields without syncdb.


Ok, you didn't tell me before.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: new field in models

2013-07-22 Thread Larry Martell
On Mon, Jul 22, 2013 at 1:53 AM, Harjot Mann  wrote:
> In django when we add a new field in existing class, we need to drop
> the table and then run the syncdb again. Is there any alternative for
> it so that we can add the field without dropping the table??

Use alter table:

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re:

2013-07-22 Thread Nikolas Stevenson-Molnar
Is that your only URLs file, or is there another one which includes that
one?

_Nik

On 7/22/2013 12:43 AM, Harjot Mann wrote:
> On Mon, Jul 22, 2013 at 3:16 AM, Nikolas Stevenson-Molnar
>  wrote:
>> Please also provide your urls.py file(s). That's frequently the culprit
>> for 404 errors.
>
> http://tny.cz/5e411aa0
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to Create an Auto Incrementing Integer Field

2013-07-22 Thread Christian Erhardt
Have a look at this post: 
http://stackoverflow.com/questions/3123796/how-to-make-an-auto-filled-and-auto-incrementing-field-in-django-admin
 
They determine the next value by calling a function called number(). In 
your case it would look something like this:

class Cliente(models.Model):
> """This is the client data model, it holds all client information. This
>docstring has to be improved."""
> def number():
> no = Cliente.objects.all().aggregate(Max(order))
> if no == None:
> return 1
> else:
> return no + 1
>
> clientcode = models.IntegerField(_('Code'), max_length=6, unique=True, 
> \
> default=number)
>
 

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: bug in multi-level multi-table inheritance?

2013-07-22 Thread Dow Street
All,

I've added a ticket for this issue:

https://code.djangoproject.com/ticket/20776

If anyone has a chance to verify that this is a bug (rather than a programming 
error on my part) I would greatly appreciate it.

Thanks!
Dow


On Jul 18, 2013, at 11:08 PM, Dow Street  wrote:

> All,
> 
> I'm seeing some unexpected behavior when using multi-level multi-table 
> inheritance.  In the example below there are three levels in the class 
> hierarchy.  When accessing the name field (which is stored in the Level1 base 
> class) from an object in Level3, the query does not seem to walk the 
> hierarchy correctly.
> 
> Note:  I am using explicitly defined id and OneToOneFields so that I can 
> specify the db_column names (for compatibility with other legacy software 
> using the same database).  Here's the models file, followed by a console log 
> where I created test objects (in an otherwise blank database):
> 
> 
> 
> # models.py
> 
> from django.db import models
> 
> class Level1(models.Model):
>  """ Top level base class """
> 
>  level1_id = models.AutoField(primary_key=True, db_column='Level1_ID')
>  name = models.CharField(max_length=32, db_column='Name', blank=True, 
> null=True)
> 
>  class Meta:
>  db_table = 'Level1'
> 
> 
> class Level2(Level1):
>  """ Middle level class """
> 
>  level2_id = models.AutoField(primary_key=True, db_column='Level2_ID')
>  level1 = models.OneToOneField('Level1', db_column='Level1_ID', 
> parent_link=True)  # parent class
> 
>  class Meta:
>  db_table = 'Level2'
> 
> 
> class Level3(Level2):
>  """ Bottom level class """
> 
>  level3_id = models.AutoField(primary_key=True, db_column='Level3_ID')
>  level2 = models.OneToOneField('Level2', db_column='Level2_ID', 
> parent_link=True)  # parent class
> 
>  class Meta:
>  db_table = 'Level3'
> 
> 
> 
> From the manage.py shell I add two objects to an otherwise empty database:
> 
> (InteractiveConsole)
> 
> from sc_test.models import *
> 
> # add Level1 object
> top1 = Level1()
> top1.name = 'Top 1'
> top1.save()
> 
> # add Level3 object
> bot1 = Level3()
> bot1.name = 'Bot 1'
> bot1.save()
> 
> # query for Level1 objects
> l1 = Level1.objects.all()
> l1
> [, ]
> 
> # query for Level2 objects
> l2 = Level2.objects.all()
> l2
> []
> 
> # query for Level3 objects
> l3 = Level3.objects.all()
> l3
> []
> 
> # Get name of first Level1 object (looks ok)
> l1[0].name
> u'Top 1'
> 
> # Get name of second Level1 object (looks ok)
> l1[1].name
> u'Bot 1'
> 
> # First Level2 object (looks ok)
> l2[0].name
> u'Bot 1'
> 
> # First Level3 object (!! WRONG !!)
> l3[0].name
> u'Top 1'
> 
> (WRONG - expected this to return u'Bot 1')
> 
> Can anyone shed some light?  Specifically, does multi-table inheritance only 
> work with one level of subclassing?  If not, is there some syntax trick I'm 
> missing, or is this a bug in the inheritance code?
> 
> 
> Thanks,
> Dow

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: django-admin.py startproject mysite error

2013-07-22 Thread gilberto dos santos alves
beside gods of olympo say that env var PYTHONPATH handle this,
please verify what your PATH and PYTHONPATH  (command echo $PATH;  echo 
$PYTHONPATH) (where this is setting depends of what shell (sh, bash, etc) 
set and use export;
when i use a shared host i have this same problems.
i solve this explicity declaring all sys.path that i want.
you could solve this using virtualenv. you could find good samples at
http://lamsonproject.org/docs/ look at virtualenv.

verify what django-admin.py you are using (which django-admin.py)

only when i used this in sys.path all things worked.


example:
===

sys.path=[]
sys.path.insert(0,"/home/your-user/myform")
sys.path.append("/home/your-user/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg")
 
sys.path.append("/home/your-user/Django-1.5-py2.7.egg") 
sys.path.append("/home/your-user/Sphinx-1.2b1-py2.7.egg")
sys.path.append("/home/your-user/docutils-0.10-py2.7.egg") 
sys.path.append("/home/your-user/Jinja2-2.7-py2.7.egg")
sys.path.append("/home/your-user/Pygments-1.6-py2.7.egg") 
sys.path.append("/home/your-user/MarkupSafe-0.18-py2.7.egg") 
sys.path.append("/home/your-user/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg")
 
sys.path.append("/home/your-user/flup-1.0.3.dev_20110405-py2.7.egg") 
sys.path.append("/home/your-user/django_threaded_multihost-1.4_1-py2.7.egg") 
sys.path.append("/home/your-user/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg")
 
sys.path.append("/home/your-user/lib/python2.7/site-packages/pip-1.2.1-py2.7.egg")
 
sys.path.append("/home/your-user/lib/python2.7/site-packages") 
sys.path.append("/home/your-user")
sys.path.append("/home/your-user/lib/python27.zip")
sys.path.append("/home/your-user/lib/python2.7")
sys.path.append("/home/your-user/lib/python2.7/plat-linux2")
sys.path.append("/home/your-user/lib/python2.7/lib-tk")
sys.path.append("/home/your-user/lib/python2.7/lib-old")
sys.path.append("/home/your-user/lib/python2.7/lib-dynload")
sys.path.append("/opt/python27/lib/python2.7")
sys.path.append("/opt/python27/lib/python2.7/plat-linux2")
sys.path.append("/opt/python27/lib/python2.7/lib-tk")


Em domingo, 21 de julho de 2013 20h38min08s UTC-3, Jay Lozier escreveu:
>
> I get this
>
> note: I have completely deleted any django packages on the my system and 
> could get any version but the dev version to even get past the first step.
> the dev 1.7 version would run django-admin.py startproject myfirstsite but 
> now python manage.py runserver does not work
> error in line 10
>
> /usr/lib/python2.7/site-packages/pymongo-2.5.1-py2.7-linux-x86_64.egg
> /usr/lib/python2.7/site-packages/bottle-0.11.6-py2.7.egg
> /usr/lib/python2.7/site-packages/translationstring-1.1-py2.7.egg
> /usr/lib/python2.7/site-packages/venusian-1.0a8-py2.7.egg
> /usr/lib/python2.7/site-packages/zope.deprecation-4.0.2-py2.7.egg
> /usr/lib/python2.7/site-packages/setuptools-0.9.6-py2.7.egg
> /home/boopers/django-trunk
> /usr/lib/python27.zip
> /usr/lib64/python2.7
> /usr/lib64/python2.7/plat-linux2
> /usr/lib64/python2.7/lib-tk
> /usr/lib64/python2.7/lib-old
> /usr/lib64/python2.7/lib-dynload
> /usr/lib64/python2.7/site-packages
> /usr/lib64/python2.7/site-packages/FontTools
> /usr/lib64/python2.7/site-packages/PIL
> /usr/local/lib64/python2.7/site-packages
> /usr/local/lib/python2.7/site-packages
> /usr/lib64/python2.7/site-packages/gst-0.10
> /usr/lib64/python2.7/site-packages/gtk-2.0
> /usr/lib64/python2.7/site-packages/input-pad-1.0
> /usr/lib/python2.7/site-packages
> /usr/lib64/python2.7/site-packages/wx-2.9.4-gtk2
>
> On Saturday, July 20, 2013 5:55:21 PM UTC-4, Jay Lozier wrote:
>>
>> Using openSUSE 12.3
>> python 2.7.3
>> django 1.5.1 installed manually and verified
>>
>> When I enter "django-admin.py startproject mysite" at the command prompt 
>> I get the following traceback:
>>
>> Traceback (most recent call last):
>> File "/usr/bin/django-admin.py", line 5, in 
>> management.execute_from_command_line()
>> File 
>> "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 
>> 453, in execute_from_command_line
>> utility.execute()
>> File 
>> "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 
>> 392, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>> File 
>> "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 
>> 272, in fetch_command
>> klass = load_command_class(app_name, subcommand)
>> File 
>> "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 
>> 77, in load_command_class
>> module = import_module('%s.management.commands.%s' % (app_name, name))
>> File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 
>> 35, in import_module
>> __import__(name)
>> File 
>> "/usr/lib/python2.7/site-packages/django/core/management/commands/startproject.py",
>>  
>> line 2, in 
>> from django.core.management.templates import TemplateCommand
>> File 
>> "/usr/lib/python2.7/site-packages/django/core/management/templates.py", 

Re: Saving data from a form.

2013-07-22 Thread Christian Erhardt
The error lies in this two rows:

form.save()
DataTable_id = DataTable.id

DataTable is the class, not the instance of the saved object! form.save() 
returns an instance of what has been saved. So your code should look like 
this:

my_new_datatable_instance = form.save()
DataTable_id = my_new_datatable_instance.id

That should do the trick


Am Montag, 22. Juli 2013 13:02:46 UTC+2 schrieb Nigel Legg:
>
> models.py:
> class DataTable(models.Model):
> datFile = models.CharField(max_length = 200)
> structFile = models.CharField(max_length = 200)
> bannerVar = models.CharField(max_length = 50)
> stubVar = models.CharField(max_length = 50)
> stubNets = models.BooleanField()
> 
> def __unicode__(self):
> return u'%s %s %s %s' % (self.datFile, self.structFile, 
> self.bannerVar, self.stubVar)
> 
> forms.py:
> class DataTableForm(forms.ModelForm):
> class Meta:
> model = DataTable
>
> views.py:
> def datatables(request):
> if request.method == 'POST':
> form = DataTableForm(request.POST)
> if form.is_valid():
> form.save()
> DataTable_id = DataTable.id
> return render(request, 'myapp/tabspec/{{DataTable_id}}.html', {
> 'DataTable_id' : DataTable.id,
> })
> else:
> form = DataTableForm()
> return render(request, 'myapp/datatables.html', {
> 'form': form,
> })
>
>
> When I input data on the form, and click "Confirm Selections", I get 
> "object DataTable has no attribute 'DataTable_id'"
> Should I be using a different method to save the data from the form to the 
> database?
>
>
> Regards,
> Nigel Legg
> 07914 740972
> http://www.trevanianlegg.co.uk
> http://twitter.com/nigellegg
> http://uk.linkedin.com/in/nigellegg
>
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to Create an Auto Incrementing Integer Field

2013-07-22 Thread Rafael E. Ferrero
Maybe extending save() method ?
Somethin like...

class your_model(models.Model):
order = models.IntegerField(default=1)

def save(self, *args, **kwargs):
if not self.id:
#here must to find the last order then sum one and save the
result
self.order=result
super(your_model, self).save(*args,**kwargs)


I'm not quite sure, but i think that this is the way.




2013/7/19 Cody Scott 

> I have a list of articles and you can control the order of the articles by
> changing the order field in the model
>
>
> order = models.IntegerField(default=1)
>
>
> I would like it to default to one more than the last article or one more
> than the largest order (since you can set the order)
>
>
> I can't use AutoField because it is only for primary keys.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Rafael E. Ferrero
Claro: (03562) 15514856

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Problem with chaining filters

2013-07-22 Thread Andrew Simpson
Perhaps something like this would give you what you need:
Pronunciation.objects.filter(word__translation='')

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to merge two lists into one form?

2013-07-22 Thread Tymoteusz Jankowski
Ok, I've found sort of solution, relatively quick so, I'm happy

CODE:

FRUITS = [
'apples', 'lemons', 'strawberries',
] # hardcoded like here or from db

ANSWERS = [
(0, u''),
(1, u'selling'),
(2, u'making'),
(3, u'both'),
] # hardcoded like here or from db

class ProblematicForm(forms.Form):
regular_field = forms.CharField()

def __init__(self, *args, **kwargs):
super(ProblematicForm, self).__init__(*args, **kwargs)
for name in FRUITS:
 # Here we add our problematic fields
 self.fields[name] = forms.ChoiceField(choices=ANSWERS)


This won't give fieldset (like in linked example), but it wouldn't have.


On Sunday, July 21, 2013 6:56:25 PM UTC+2, Tymoteusz Jankowski wrote:
>
> I have 2 things:
> - list of fruits (eg.: apples, lemons, strawberries)
> - list of answers (eg.: 'selling', 'making', 'both')
>
> How can i merge these lists into django form which products something like 
> the html here .
>
> The desired form would allow user to pick an ONE answer ('selling', 
> 'making', 'both') for each fruit (apples, lemons, starberries)
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Can I only have one "get_queryset" per Viewpage?

2013-07-22 Thread Mário Neto
Hi, you can separate your querysets in get_context_data method.
See:
https://docs.djangoproject.com/en/dev/ref/class-based-views/mixins-simple/#django.views.generic.base.ContextMixin.get_context_data


2013/7/22 Pepsodent Cola 

> Hi,
>
> Can I only have one "get_queryset" for each Viewpage?
> If I wanted to add another database list on the same Viewpage how would
> that code look like for my Django *views.py* file?
>
> Example:
> https://docs.djangoproject.com/en/1.5/intro/tutorial04/#amend-views
>
> from polls.models import Choice, Poll
>
> class IndexView(generic.ListView):
> template_name = 'polls/index.html'
> *context_object_name = 'latest_poll_list'*
>
> *def get_queryset(self):*
> """Return the last five published polls."""
> return Poll.objects.order_by('-pub_date')[:5]
>
>
>
> I mean will "context_object_name" be able to separate between several
> "get_queryset(self)"?
> Because I want to have several different poll_lists on the same Viewpage.
>
> context_object_name = 'latest_poll_list'
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Att. *Mário Araújo Chaves Neto*
*Programmer, Designer and U.I. Engineer*
*
*
*MBA in Design Digital* - 2008 - FIC
*Analysis and Systems Development* - 2011 - Estácio
*D**esign and Implementation of Internet Environments* - 2003 - FIC

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: request.user returning AnonymousUser

2013-07-22 Thread l33t

Hello,

The problem is fixed. I was not using the get_user method in the custom 
authentication backend properly.

Best Regards,
Goose.


On Friday, July 19, 2013 1:04:22 PM UTC+2, l33t wrote:
>
>
> Hello,
>
> I have a custom authentication backend and a custom user model. The 
> authentication() method in the custom authentication backend returns the 
> custom user after successful authentication. Once authenticated, I use 
> login from django.contrib.auth to set the sessionid for the custom user.
> Now, I create a method as shown below:
> *
> def myview(request):
> if not request.user.is_authenticated():
> return render(request,'auth_fail.html')
> else:
> return render(request,'auth_success.html')*
>
> This is always returning not authenticated. When I print request.user, it 
> shows AnonymousUser. But, when i print request.COOKIES, i can see the 
> sessionid which was set by the login method from django.contrib.auth.
>
> So, my question is how can I check if the custom user is authenticated or 
> not?. 
> Thanks in advance.
>
> Best Regards,
> Goose. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




(Noob) - filtering spanning relationship not working

2013-07-22 Thread Lukas Kawerau


I want to find the number of articles for which a specific user has created 
articlehistoryrecords.
The models for that look like this:

class Article(models.Model):
"""The basic entity of this app.)"""
documentID = models.CharField(blank=True, max_length=1000)
cowcode = models.IntegerField(blank=True, null=True)
pubdate = models.DateField(default=datetime.datetime.today)
headline = models.CharField(blank=True, max_length=1500)
source = models.CharField(blank=True, max_length=5000)
text = models.TextField(blank=True, max_length=100)
assignments = models.ManyToManyField(Assignment)

class Meta:
ordering = ['pubdate']

def __unicode__(self):
return self.headline
class ArticleHistory(models.Model):
"""(Modelname description)"""
article = models.ForeignKey(Article, related_name='Article History')
coder = models.ForeignKey(User, related_name='Article History')
last_updated = models.DateTimeField(default=datetime.datetime.now)

def __unicode__(self):
return self.last_updated

The way I'm trying to do this at the moment is like this:

assignment.finished_articles = 
Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date),
 articlehistory__coder=request.user.id).count()

This doesn't work, however and exhibits another weird behaviour:
I try to do this:

for assignment in assignments:
country = assignment.country.cowcode
start_date = assignment.start_date
end_date = assignment.end_date
articles = 
Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date)).select_related()
assignment.article_num = articles.count()
#assignment.finished_articles = 
Article.objects.filter(cowcode=country).filter(pubdate__range=(start_date,end_date),
 articlehistory__coder=request.user.id).count()

This works fine, unless I try to include finished_articles, then article_num 
gets 
shortened to one result.

It would be really great if anyone has a pointer to who to solve this.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: new field in models

2013-07-22 Thread Harjot Mann
On Mon, Jul 22, 2013 at 2:11 PM, Floor Tile  wrote:
> Hello Harjot
>
> I think you should look at South: south.aeracode.org/
>
> For the docs you can go to: south.readthedocs.org/
>
> Hope it helps


Hello Floor, thanks.

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Can I only have one "get_queryset" per Viewpage?

2013-07-22 Thread Pepsodent Cola
Hi,

Can I only have one "get_queryset" for each Viewpage?
If I wanted to add another database list on the same Viewpage how would 
that code look like for my Django *views.py* file?

Example:
https://docs.djangoproject.com/en/1.5/intro/tutorial04/#amend-views

from polls.models import Choice, Poll

class IndexView(generic.ListView):
template_name = 'polls/index.html'
*context_object_name = 'latest_poll_list'*

*def get_queryset(self):*
"""Return the last five published polls."""
return Poll.objects.order_by('-pub_date')[:5]



I mean will "context_object_name" be able to separate between several 
"get_queryset(self)"?
Because I want to have several different poll_lists on the same Viewpage.

context_object_name = 'latest_poll_list'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: new field in models

2013-07-22 Thread Floor Tile
Hello Harjot

I think you should look at South: south.aeracode.org/

For the docs you can go to: south.readthedocs.org/

Hope it helps


On Mon, Jul 22, 2013 at 9:53 AM, Harjot Mann wrote:

> In django when we add a new field in existing class, we need to drop
> the table and then run the syncdb again. Is there any alternative for
> it so that we can add the field without dropping the table??
>
> --
> Harjot Kaur Mann
> Blog: http://harjotmann.wordpress.com/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: new field in models

2013-07-22 Thread Satinderpal Singh
On Jul 22, 2013 1:23 PM, "Harjot Mann"  wrote:
>
> In django when we add a new field in existing class, we need to drop
> the table and then run the syncdb again. Is there any alternative for
> it so that we can add the field without dropping the table
South is an alternative, it creates table fields without syncdb.

--
Satinderpal Singh

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




new field in models

2013-07-22 Thread Harjot Mann
In django when we add a new field in existing class, we need to drop
the table and then run the syncdb again. Is there any alternative for
it so that we can add the field without dropping the table??

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re:

2013-07-22 Thread Harjot Mann
On Mon, Jul 22, 2013 at 3:16 AM, Nikolas Stevenson-Molnar
 wrote:
> Please also provide your urls.py file(s). That's frequently the culprit
> for 404 errors.


http://tny.cz/5e411aa0

--
Harjot Kaur Mann
Blog: http://harjotmann.wordpress.com/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: create random string for username

2013-07-22 Thread Derek
Re URLs

Have look at 
http://itekblog.com/django-url-dispatcher-routing-beginners-tutorial/  ... 
and  bear in mind that the 'r' and the '^' are not directly related and 
serve two purposes.  

The very basic "overview" of Django is that urls point to views; views 
typically make use of models (and other bits-and-pieces such as forms or 
business logic code) to help handle data going in and/or out; and models 
are mapped to tables in your database (and themselves have code to help 
ensure data integrity).  Very logical and not *too* hard!

Without those layers, your web app ends up being a huge mish-mash of code 
and data and HTML ... like "old skool" PHP.  Easy to start off, but a 
nightmare to maintain as it gets more complex.

Derek

On Saturday, 20 July 2013 17:17:06 UTC+2, Randy Baxley wrote:
>
> The Django tutorial is not quite making it for me.  This is a very 
> complicated language and all the pieces seem to not match up for me.  This 
> I think is my fault and most of it seems to be in the use of the r hat for 
> root and exactly how that points to views, models and dbs.  I may get there 
> but it is not easy without someone to be a sort of guide.  Each time though 
> I go into settings or one of the other files they get a perception of being 
> more familiar and thus shorter.  While doing some of those I say a key set 
> to fals for allow profanity but not sure what all that filter has passed 
> through it.
>
>
> On Sat, Jul 20, 2013 at 8:20 AM, Tim Chase 
>  > wrote:
>
>> On 2013-07-18 20:53, Sivaram R wrote:
>> >   While saving these forms instance,is it possible to create a
>> > random string for username field.How to do this,any sample would be
>> > great choice.
>>
>> You can.  Assigning random usernames isn't usually considered a very
>> nice thing to do to users, but assuming you have a valid use-case
>> for it, it's just simple Python:
>>
>>   import random
>>   import string
>>   def random_username(characters=string.ascii_lowercase, length=10):
>> return ''.join(
>>   random.choice(characters)
>>   for _ in range(length)
>>   )
>>
>> You might also want to post-process to check for profanity in it, as
>> you you don't (usually) want to assign profanity as a username:
>>
>>   BAD_WORDS = [ ... ] # all in uppercase
>>   while True:
>> username = random_username()
>> normalized_username = random_username.upper()
>> for word in BAD_WORDS:
>>   if word in normalized_username:
>> break
>> else: # note this is at the indentation level of the "for", not "if"
>>   break
>>   print "Username:", username
>>
>> It's not a perfect check, but it will eliminate the obviously
>> problematic ones based on your black-list
>>
>> -tkc
>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.