Form field label template

2018-02-09 Thread jorrit787
I want to improve the look of my forms with Materialize CSS 
(http://materializecss.com/forms.html), which requires some fields to have 
a div with class input-field around the input AND the label. I figured I 
could use the new template-based widget rendering, but to my surprise those 
templates don't include the labels. Is there a way to achieve this without 
rendering every field manually?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/758f-fae1-4475-85f5-1144241837e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Displaying Categories / Subcategories (Tango with Django Example)

2017-05-12 Thread jorrit787
Both, actually. The OP is looping through his cats and pages querysets 
multiple times unnecessarily. That can get very inefficient as those 
database tables get bigger.


On Friday, May 12, 2017 at 6:04:01 PM UTC+2, sacrac wrote:
>
> {% regroup %} is elegantly or more optimized???
>
> On Fri, May 12, 2017 at 5:05 AM, > wrote:
>
>> You can look into the {% regroup %} template tag. It will do what you are 
>> trying to do more elegantly.
>>
>>
>>
>> On Wednesday, May 10, 2017 at 7:40:26 PM UTC+2, Michael Smith wrote:
>>>
>>> I'm following the latest Tango book and was experimenting with different 
>>> ways of looping through categories and subcategories to create a list.  I 
>>> have a 'Category' and 'Page' model, where Page has a foreign key to 
>>> Category's ID.  To display a list with sub-bullets I simply passed all 
>>> categories and pages to a template and then looped through Page:
>>>
>>> 
>>>   {% if cats %}
>>> {% for c in cats %}
>>>   {% if c == act_cat %}
>>>   {{ c.name 
>>> }}
>>>   
>>>   {% else %}
>>>   {{ c.name }}
>>>   {% endif %}
>>> {% for p in pages %}
>>>   {% if p.category_id == c.pk %}
>>> {{ p.title }}
>>>   {% endif %}
>>> {% endfor %}
>>> {% endfor %}
>>>   {% else %}
>>> There are no categories present.
>>>   {% endif %}
>>> 
>>>
>>> Is this considered the best way to do such a thing?
>>>
>>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/96558026-ac69-4c7c-bb98-cee43dddee82%40googlegroups.com
>>  
>> 
>> .
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> att.
> Carlos Rocha
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8dad860e-39c7-4a43-99e8-0931d6813725%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Displaying Categories / Subcategories (Tango with Django Example)

2017-05-12 Thread jorrit787
You can look into the {% regroup %} template tag. It will do what you are 
trying to do more elegantly.


On Wednesday, May 10, 2017 at 7:40:26 PM UTC+2, Michael Smith wrote:
>
> I'm following the latest Tango book and was experimenting with different 
> ways of looping through categories and subcategories to create a list.  I 
> have a 'Category' and 'Page' model, where Page has a foreign key to 
> Category's ID.  To display a list with sub-bullets I simply passed all 
> categories and pages to a template and then looped through Page:
>
> 
>   {% if cats %}
> {% for c in cats %}
>   {% if c == act_cat %}
>   {{ c.name 
> }}
>   
>   {% else %}
>   {{ c.name }}
>   {% endif %}
> {% for p in pages %}
>   {% if p.category_id == c.pk %}
> {{ p.title }}
>   {% endif %}
> {% endfor %}
> {% endfor %}
>   {% else %}
> There are no categories present.
>   {% endif %}
> 
>
> Is this considered the best way to do such a thing?
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/96558026-ac69-4c7c-bb98-cee43dddee82%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django 1.11 released

2017-04-05 Thread jorrit787
Is the required version of Pillow pinned at 4.0.0? I upgraded to Django 
1.11 and from Pillow 4.0.0 to 4.1.0 but now Django doesn't start because it 
says I can't use ImageField without installing Pillow. Downgrading to 
Pillow 4.0.0 fixes this.


On Tuesday, April 4, 2017 at 6:09:40 PM UTC+2, Tim Graham wrote:
>
> Django 1.11, the next long-term support release, is now available:
>
> https://www.djangoproject.com/weblog/2017/apr/04/django-111-released/
>
> With the release of Django 1.11, Django 1.10 has reached the end of 
> mainstream support. The final minor bugfix release (1.10.7) was issued 
> today. Django 1.10 will receive security and data loss fixes for another 
> eight months until December 2017.
>
> Django 1.9 has reached the end of extended support. The final security 
> release (1.9.13) was issued today. All Django 1.9 users are encouraged to 
> upgrade to Django 1.10 or later.
>
> See the downloads page [1] for a table of supported versions and the 
> future release schedule.
>
> [1] https://www.djangoproject.com/download/#supported-versions
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20403ada-0688-4192-9aef-8904f10d43d8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Making email required

2017-02-01 Thread jorrit787
You can define a single form to use for creating and updating users like 
this:

class CustomUserChangeForm(UserChangeForm): 
 class Meta: 
 

 model = User 
 

 fields = ('email', 'password', 'first_name', 'last_name', 'photo', 
'is_active', 'is_staff', 'user_permissions') 
 

 
 
 

 
 
 

class CustomUserAdmin(UserAdmin): 
 

 # Override standard fields 
 

 form = CustomUserChangeForm 
 

 fieldsets = None 
 

 add_fieldsets = (None, { 
 

 'classes': ('wide',), 
 

 'fields': ('email', 'password1', 'password2', 'first_name', 'last_name', 
'is_staff'), 
 
 }),

Setting fieldsets = None on the CustomUserAdmin makes it inherit the fields 
from your form to use when updating a user, and setting add_fieldsets to 
the fields you want lets you specify the fields you want to use when 
creating a user.

The problem you are having is that Django only recognizes a field named 
'password' as a special case, and not 'password1' and 'password2', so the 
latter two are only to be used when you actually do need to input the 
unhashed password,
 

On Tuesday, January 31, 2017 at 9:58:27 PM UTC+1, larry@gmail.com wrote:
>
> I want to make the email field required in the user admin add and 
> change pages. Following some posts I read on stackoverflow I did this: 
>
> class MyUserCreationForm(UserCreationForm): 
> def __init__(self, *args, **kwargs): 
> super(MyUserCreationForm, self).__init__(*args, **kwargs) 
> # make user email field required 
> self.fields['email'].required = True 
>
> class UserAdmin(BaseUserAdmin): 
> form = MyUserCreationForm 
> add_form = MyUserCreationForm 
> add_fieldsets = ((None, {'fields': ('username', 'email', 
> 'password1', 'password2'), 'classes': ('wide',)}),) 
>
> admin.site.unregister(User) 
> admin.site.register(User, UserAdmin) 
>
> This works fine in add user, but in change user I get the user's 
> encrypted password shown in the password field, instead of what you 
> normally see: 
>
> algorithm: pbkdf2_sha256 iterations: 24000 salt: ** hash: 
> ** 
> Raw passwords are not stored, so there is no way to see this user's 
> password, but you can change the password using this form. 
>
> And when I try to save from the change screen it says "Please correct 
> the errors below." even though there are no errors shown. 
>
> How can I fix these issues in the change form? 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fa5d3129-06ca-4d83-9309-322411ffa0ed%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "Polls" app in Django Beginners' Tutorial

2017-01-20 Thread jorrit787
Did you set a pub_date on the questions you created? Since the field 
doesn't have a default value it will remain empty and have no effect on 
ordering unless you explicitly set pub_date=timezone,now() every time you 
create a question.

On Friday, January 20, 2017 at 2:30:37 PM UTC+1, DjangoUserDM wrote:
>
> Here it is:
>
> class Question(models.Model):
> question_text = models.CharField(max_length=200)
> pub_date = models.DateTimeField('date published')
>
> def was_published_recently(self):
> now = timezone.now()
> return now - datetime.timedelta(days=1) <= self.pub_date <= now
>
> def __str__(self):
> return self.question_text
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/16750999-ac65-48b0-87c4-2fe6ce11a739%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Tutorial Part 5, Test detail view with a past question failure.

2017-01-20 Thread jorrit787
You mean that after you make the changes the tutorial gives you the test 
still fails? It is supposed to fail the first time before you make the 
changes.


On Thursday, January 19, 2017 at 8:21:38 PM UTC+1, Vpeguero wrote:
>
> I'm currently working through the django tutorial for v1.10. On part 5 the 
> final test that is created is raising an assertion error as follows:
>
> Creating test database for alias 'default'...
> .F
> ==
> FAIL: test_detail_view_with_a_past_question 
> (polls.tests.QuestionIndexDetailTests)
> --
> Traceback (most recent call last):
>   File "/home/dufort/code/django-tutorials/mysite/polls/tests.py", line 
> 122, in test_detail_view_with_a_past_question
> self.assertContains(response, past_question.question_text)
>   File 
> "/tmp/bash-venv/8918/lib/python2.7/site-packages/django/test/testcases.py", 
> line 382, in assertContains
> self.assertTrue(real_count != 0, msg_prefix + "Couldn't find %s in 
> response" % text_repr)
> AssertionError: Couldn't find 'Past Question.' in response
>
> --
> Ran 10 tests in 0.045s
>
> FAILED (failures=1)
> Destroying test database for alias 'default'...
>
>
>
> The following is the specific test being used 
>
> import datetime
>
> from django.utils import timezone
> from django.test import TestCase
> from django.urls import reverse
>
> from .models import Question
>
> ...
>
> def create_question(question_text, days):
> """
> Creates a question with the given 'question_text' and published the
> given number of 'days'offset to now (negative for question published 
> in the past,
> positive for questions that have yet to be published.
> """
> time = timezone.now() + datetime.timedelta(days=days)
> return Question.objects.create(question_text=question_text, 
> pub_date=time)
>
>
> ...
>
> class QuestionIndexDetailTests(TestCase):
>
> ...
>
> def test_detail_view_with_a_past_question(self):
> """
> The detail view of a question with a pub_date in the past should
> display the question's text.
> """
> past_question = create_question(question_text='Past Question.', 
> days=-5)
> url = reverse('polls:detail', args=(past_question.id,))
> response = self.client.get(url)
> self.assertContains(response, past_question.question_text)
>
>
>
>
> Views:
> from django.shortcuts import render, get_object_or_404
> from django.http import HttpResponseRedirect
> from django.urls import reverse
> from django.views import generic
> from django.utils import timezone
>
> from .models import Choice, Question
> # Create your views here.
>
> class IndexView(generic.ListView):
> template_name = 'polls/index.html'
> context_object_name = 'latest_question_list'
>
> def get_queryset(self):
> """ 
> Return the last five published questions
> (not including those set to be published in the future.)
> """
> return Question.objects.filter(
> pub_date__lte=timezone.now()
> ).order_by('-pub_date')[:5]
>
> class DetailView(generic.DetailView):
> model = Question
> template_name = 'polls/detail.html'
>
> def get_queryset(self):
> """
> Excludes any questions that aren't published yet.
> """
> return Question.objects.filter(pub_date__lte=timezone.now())
>
> class ResultsView(generic.DetailView):
> model = Question
> template_name = 'polls/results.html'
>
> def vote(request, question_id):
> question = get_object_or_404(Question, pk=question_id)
> try:
> selected_choice = 
> question.choice_set.get(pk=request.POST['choice'])
> except (KeyError, Choice.DoesNotExist):
> return render(request, 'polls/detail.html', {
> 'question': question,
> 'error_message': "You didn't select a choice.",
> })
> else:
> selected_choice.votes += 1
> selected_choice.save()
> return HttpResponseRedirect(reverse('polls:results', args=(
> question.id,)))  
> 
> 
>   
>   
>  
> I've decided to move forward with the tutorials. I am having trouble 
> identifying if this is a bug in the tutorial itself or if there is just 
> something missing in my code that is causing 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-

Re: "Polls" app in Django Beginners' Tutorial

2017-01-20 Thread jorrit787
Can you show your Question model?


On Friday, January 20, 2017 at 1:33:33 PM UTC+1, DjangoUserDM wrote:
>
> No, definitely didn't!
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dad0d911-83fc-4a84-8484-c14195f73eea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: "Polls" app in Django Beginners' Tutorial

2017-01-20 Thread jorrit787
Perhaps you forgot the '-' before pub_date?

On Thursday, January 19, 2017 at 8:21:32 PM UTC+1, DjangoUserDM wrote:
>
> I have a question about the "Polls" app, as described in the Django 
> Beginners' Tutorial, https://docs.djangoproject.com/en/1.10/intro/.  In 
> tutorial 3, the index view contains the following code:
>
>  
>
> latest_question_list = Question.objects.order_by('-pub_date')[:5]
>
>  
>
> It is stated that this produces the latest 5 questions according to 
> publication date.  The '-' in front of 'pub_date' is intended to return the 
> questions in descending rather than ascending order of publication date.  
> Yet when I tried this out, it returns the *earliest* 5 questions in my 
> database.  Is this an error, or (more likely), have I done something wrong?
>
>  
>
> Thanks for any advice!
>
>  
>
> David
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5aa803ed-5305-4004-a28f-5609869f8f56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: readonly and autofocus support in form fields?

2017-01-19 Thread jorrit787
I think the problem here is with ModelForms. Where would you define these 
properties for ModelForms? Putting them in your Model classes doesn't make 
sense because it violates loose coupling between models and 
forms/templates. It's already quite peculiar that Model fields can have a 
blank=True attribute.

If you haven't already, look into django-crispy-forms. It gives you much 
more granular control over your forms while maintaining loose coupling and 
OO-syntax.


On Thursday, January 19, 2017 at 5:11:47 AM UTC+1, Norberto Bensa wrote:
>
> Hello, 
>
> I usually need to make form fields readonly or autofocus (the app I'm 
> developing right now has a lot of these). 
>
> While I can do it in the form or a custom field, I'm wondering why 
> there's no support for these attributes out-of-the-box (btw, there's 
> support for disabled). 
>
> TIA, 
> Norberto 
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ca2a8a4-a8b2-48ed-b80c-e0931db5b93e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating a sample poll app 2

2017-01-17 Thread jorrit787
Because you need to import the Question model from the models.py file 
before you can register it in the admin. "from .models import X" means 
"import X from the file models which is in the same directory as the 
current file".


On Tuesday, January 17, 2017 at 3:18:47 PM UTC+1, Rachit Tibrewal wrote:
>
> Why is '.models' in the documentation? 
> ##polls/admin.py 
> from django.contrib import admin 
>
> from .models import Question 
>
> admin.site.register(Question)

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc818be1-8a20-46f5-9661-0cfb2585a763%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: models foreign key

2017-01-12 Thread jorrit787
What exactly isn't working? Are you getting an error message?

I can see a few potential problems:

   - You're missing a quotation mark around Author_code in the *to_field* 
   parameter;
   - The fields on both models have the same name, this might cause 
   problems.



On Thursday, January 12, 2017 at 10:40:43 AM UTC+1, jeffreyequizuvero wrote:
>
>
>
> *This is about the models foreign key, I have two tables and i used 
> foreign key to connect these tables however after i did migration it's not 
> working. Is there any wrong with my code? *
>
> *please help, Thanks. *
>
>
> class *Author*(models.Model):
> *Author_code = models.CharField(max_length=50,unique=True)*
> Author_Fname = models.CharField(max_length=30, blank=True, null=True)
> Author_Mname = models.CharField(max_length=30, blank=True, null=True)
> Author_Lname = models.CharField(max_length=30, blank=True, null=True)
>
> class Meta:
> # managed = False
> db_table = 'Author'
>
>
> class *Book*(models.Model):
>
> Book_code = models.CharField(max_length=50, blank=True, 
> default=user_code_key,unique=True)
> *Author_code = models.ForeignKey(Author, to_field=Author_code', 
> on_delete=models.CASCADE)*
> Book_title = models.CharField(max_length=50, blank=True, null=True)
>
> class Meta:
>  #   managed = False
> db_table = 'Book'
>
>
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fb32e401-f1a6-4180-a49a-12c86b09bed5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: DateField default value in SQLite and Postgres

2017-01-04 Thread jorrit787
I use SQLite locally for development and Postgres in production. So when my 
migration runs fine locally I expect it to also work fine when I upload it 
5 minutes later and try to apply it to my Postgres database.


On Wednesday, January 4, 2017 at 3:59:52 PM UTC+1, Avraham Serour wrote:
>
> well the ORM does abstract the different API's for each backend, you may 
> give an datetime object and it will take care to format to the appropriate 
> thing the backend needs.
>
> you are right that it does not check the type of the value passed, it is a 
> valid point that the library should check the type, but on the other hand 
> if one is using sqlite why enforce stricter rules than the backend I'm 
> using just because one other backend has a problem with it?
>
> Also this is python, if it quacks like a duck then it is a duck, right?
>
>
> On Wed, Jan 4, 2017 at 3:24 PM, Antonis Christofides <
> ant...@djangodeployment.com > wrote:
>
>> Instead of default='17/06/2017', you should write default=datetime(2017, 
>> 6, 17). The bug in Django (if it is a bug, and I think it is) is that it 
>> does not require you to do so. There's probably a reason for it, but I 
>> don't really know..
>>
>> Regards,
>>
>> Antonis
>>
>> Antonis Christofideshttp://djangodeployment.com
>>
>>
>> On 01/04/2017 03:10 PM, jorr...@gmail.com  wrote:
>>
>> I thought the whole point of an ORM was to abstract away differences 
>> between backends... That's why this seems like a bug to me.
>>
>>
>> On Wednesday, January 4, 2017 at 1:02:07 PM UTC+1, Avraham Serour wrote: 
>>>
>>> Well this is the reality right now, if you think the framework is acting 
>>> wrong you may file a bug report. 
>>>
>>> In my opinion the wrong side of the equation is you, the framework is 
>>> just passing the value you assigned, the ORM tries to make a consistent API 
>>> between backends but I wouldn't really expect the same behaviour from all 
>>> backends, after all they are different backends, they will have different 
>>> bugs, performance and ultimately different behaviour
>>>
>>> On Wed, Jan 4, 2017 at 1:47 PM,  wrote:
>>>
 The fact that some backends are more forgiving is exactly my point. 
 Maybe the migrations engine should always force a datetime object (or at 
 least a -MM-DD notation) to make it work consistently on all backends.


 On Wednesday, January 4, 2017 at 11:35:38 AM UTC+1, Avraham Serour 
 wrote: 
>
> DateField is a representation of datetime.date, so you should assign a 
> date object and not a string, sqlite is more forgiving and doesn't 
> complain 
> so much in many cases
>
> On Wed, Jan 4, 2017 at 12:13 AM,  wrote:
>
>> This field:
>>
>> activity_date = models.DateField('Datum', default='17/06/2017')
>>
>>
>> Results in this migration:
>>
>> class Migration(migrations.Migration):
>>
>> dependencies = [
>> ('activities', '0006_auto_20161231_1703'),]
>>
>> operations = [
>> migrations.AlterField(
>> model_name='activity',name='activity_date',  
>>   field=models.DateField(default='17/06/2017', 
>> verbose_name='Datum'),),]
>>
>> Which works fine on SQLite but gives this error on Postgres: 
>> Operations to perform:   Apply all migrations: activities, 
>> addressbook, admin, auth, contenttypes, sessions, users Running 
>> migrations:   Applying activities.0007_auto_20170103_2309...Traceback 
>> (most recent call last):   File "manage.py", line 22, in
>>   execute_from_command_line(sys.argv)   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
>> , line 367, in execute_from_command_line utility.execute()   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
>> , line 359, in execute self.fetch_command(subcommand).
>> run_from_argv(self.argv)   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
>> , line 294, in run_from_argv self.execute(*args, **cmd_options) 
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
>> , line 345, in execute output = self.handle(*args, **options)   
>> File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py"
>> , line 204, in handle fake_initial=fake_initial,   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
>> , line 115, in migrate state = self._migrate_all_forwards(state, 
>> plan, full_plan, fake=fake, fake_initial=fake_initial)   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
>> , line 145, in _migrate_all_forwards state = self.apply_migration
>> (state, migration, fake=fake, fake_initial=fake_

Re: DateField default value in SQLite and Postgres

2017-01-04 Thread jorrit787
I thought the whole point of an ORM was to abstract away differences 
between backends... That's why this seems like a bug to me.


On Wednesday, January 4, 2017 at 1:02:07 PM UTC+1, Avraham Serour wrote:
>
> Well this is the reality right now, if you think the framework is acting 
> wrong you may file a bug report.
>
> In my opinion the wrong side of the equation is you, the framework is just 
> passing the value you assigned, the ORM tries to make a consistent API 
> between backends but I wouldn't really expect the same behaviour from all 
> backends, after all they are different backends, they will have different 
> bugs, performance and ultimately different behaviour
>
> On Wed, Jan 4, 2017 at 1:47 PM, > wrote:
>
>> The fact that some backends are more forgiving is exactly my point. Maybe 
>> the migrations engine should always force a datetime object (or at least a 
>> -MM-DD notation) to make it work consistently on all backends.
>>
>>
>> On Wednesday, January 4, 2017 at 11:35:38 AM UTC+1, Avraham Serour wrote:
>>>
>>> DateField is a representation of datetime.date, so you should assign a 
>>> date object and not a string, sqlite is more forgiving and doesn't complain 
>>> so much in many cases
>>>
>>> On Wed, Jan 4, 2017 at 12:13 AM,  wrote:
>>>
 This field:

 activity_date = models.DateField('Datum', default='17/06/2017')


 Results in this migration:

 class Migration(migrations.Migration):

 dependencies = [
 ('activities', '0006_auto_20161231_1703'),
 ]

 operations = [
 migrations.AlterField(
 model_name='activity',
 name='activity_date',
 field=models.DateField(default='17/06/2017', 
 verbose_name='Datum'),
 ),
 ]


 Which works fine on SQLite but gives this error on Postgres:

 Operations to perform:
   Apply all migrations: activities, addressbook, admin, auth, 
 contenttypes, sessions, users
 Running migrations:
   Applying activities.0007_auto_20170103_2309...Traceback (most recent 
 call last):
   File "manage.py", line 22, in 
 execute_from_command_line(sys.argv)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
 , line 367, in execute_from_command_line
 utility.execute()
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
 , line 359, in execute
 self.fetch_command(subcommand).run_from_argv(self.argv)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
 , line 294, in run_from_argv
 self.execute(*args, **cmd_options)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
 , line 345, in execute
 output = self.handle(*args, **options)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py"
 , line 204, in handle
 fake_initial=fake_initial,
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
 , line 115, in migrate
 state = self._migrate_all_forwards(state, plan, full_plan, fake=
 fake, fake_initial=fake_initial)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
 , line 145, in _migrate_all_forwards
 state = self.apply_migration(state, migration, fake=fake, 
 fake_initial=fake_initial)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
 , line 244, in apply_migration
 state = migration.apply(state, schema_editor)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/migration.py"
 , line 129, in apply
 operation.database_forwards(self.app_label, schema_editor, 
 old_state, project_state)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py"
 , line 204, in database_forwards
 schema_editor.alter_field(from_model, from_field, to_field)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
 , line 495, in alter_field
 old_db_params, new_db_params, strict)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/postgresql/schema.py"
 , line 117, in _alter_field
 new_db_params, strict,
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
 , line 578, in _alter_field
 new_default = self.effective_default(new_field)
   File 
 "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
 , line 221, in effective_default
 default = field.get_db_prep_save(default, self.connection)
   File 
 "/

Re: DateField default value in SQLite and Postgres

2017-01-04 Thread jorrit787
The fact that some backends are more forgiving is exactly my point. Maybe 
the migrations engine should always force a datetime object (or at least a 
-MM-DD notation) to make it work consistently on all backends.


On Wednesday, January 4, 2017 at 11:35:38 AM UTC+1, Avraham Serour wrote:
>
> DateField is a representation of datetime.date, so you should assign a 
> date object and not a string, sqlite is more forgiving and doesn't complain 
> so much in many cases
>
> On Wed, Jan 4, 2017 at 12:13 AM, > wrote:
>
>> This field:
>>
>> activity_date = models.DateField('Datum', default='17/06/2017')
>>
>>
>> Results in this migration:
>>
>> class Migration(migrations.Migration):
>>
>> dependencies = [
>> ('activities', '0006_auto_20161231_1703'),
>> ]
>>
>> operations = [
>> migrations.AlterField(
>> model_name='activity',
>> name='activity_date',
>> field=models.DateField(default='17/06/2017', 
>> verbose_name='Datum'),
>> ),
>> ]
>>
>>
>> Which works fine on SQLite but gives this error on Postgres:
>>
>> Operations to perform:
>>   Apply all migrations: activities, addressbook, admin, auth, 
>> contenttypes, sessions, users
>> Running migrations:
>>   Applying activities.0007_auto_20170103_2309...Traceback (most recent 
>> call last):
>>   File "manage.py", line 22, in 
>> execute_from_command_line(sys.argv)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
>> , line 367, in execute_from_command_line
>> utility.execute()
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
>> , line 359, in execute
>> self.fetch_command(subcommand).run_from_argv(self.argv)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
>> , line 294, in run_from_argv
>> self.execute(*args, **cmd_options)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
>> , line 345, in execute
>> output = self.handle(*args, **options)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py"
>> , line 204, in handle
>> fake_initial=fake_initial,
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
>> , line 115, in migrate
>> state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
>> fake_initial=fake_initial)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
>> , line 145, in _migrate_all_forwards
>> state = self.apply_migration(state, migration, fake=fake, 
>> fake_initial=fake_initial)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
>> , line 244, in apply_migration
>> state = migration.apply(state, schema_editor)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/migration.py"
>> , line 129, in apply
>> operation.database_forwards(self.app_label, schema_editor, old_state, 
>> project_state)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py"
>> , line 204, in database_forwards
>> schema_editor.alter_field(from_model, from_field, to_field)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
>> , line 495, in alter_field
>> old_db_params, new_db_params, strict)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/postgresql/schema.py"
>> , line 117, in _alter_field
>> new_db_params, strict,
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
>> , line 578, in _alter_field
>> new_default = self.effective_default(new_field)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
>> , line 221, in effective_default
>> default = field.get_db_prep_save(default, self.connection)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
>> , line 755, in get_db_prep_save
>> prepared=False)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
>> , line 1280, in get_db_prep_value
>> value = self.get_prep_value(value)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
>> , line 1275, in get_prep_value
>> return self.to_python(value)
>>   File 
>> "/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
>> , line 1250, in to_python
>> params={'value': value},
>> django.core.exceptions.ValidationError: ["'17/06/2017' waarde heeft een 
>> ongeldige datumnotatie. Deze moet in de -MM-DD notatie opgegeven 
>> worden."]
>>
>>
>>
>> The error says: "DATE" has an invalid date notation. It must be submitted 
>> as -MM-DD notation. Timezone/locale is Europe

Re: DateField default value in SQLite and Postgres

2017-01-03 Thread jorrit787
This field:

activity_date = models.DateField('Datum', default='17/06/2017')


Results in this migration:

class Migration(migrations.Migration):

dependencies = [
('activities', '0006_auto_20161231_1703'),
]

operations = [
migrations.AlterField(
model_name='activity',
name='activity_date',
field=models.DateField(default='17/06/2017', verbose_name='Datum'),
),
]


Which works fine on SQLite but gives this error on Postgres:

Operations to perform:
  Apply all migrations: activities, addressbook, admin, auth, contenttypes, 
sessions, users
Running migrations:
  Applying activities.0007_auto_20170103_2309...Traceback (most recent call 
last):
  File "manage.py", line 22, in 
execute_from_command_line(sys.argv)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
, line 367, in execute_from_command_line
utility.execute()
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/__init__.py"
, line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
, line 294, in run_from_argv
self.execute(*args, **cmd_options)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/base.py"
, line 345, in execute
output = self.handle(*args, **options)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/core/management/commands/migrate.py"
, line 204, in handle
fake_initial=fake_initial,
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
, line 115, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, 
fake_initial=fake_initial)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
, line 145, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=
fake_initial)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/executor.py"
, line 244, in apply_migration
state = migration.apply(state, schema_editor)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/migration.py"
, line 129, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, 
project_state)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/migrations/operations/fields.py"
, line 204, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
, line 495, in alter_field
old_db_params, new_db_params, strict)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/postgresql/schema.py"
, line 117, in _alter_field
new_db_params, strict,
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
, line 578, in _alter_field
new_default = self.effective_default(new_field)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/backends/base/schema.py"
, line 221, in effective_default
default = field.get_db_prep_save(default, self.connection)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 755, in get_db_prep_save
prepared=False)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 1280, in get_db_prep_value
value = self.get_prep_value(value)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 1275, in get_prep_value
return self.to_python(value)
  File 
"/webapps/mzg/venv/lib/python3.5/site-packages/django/db/models/fields/__init__.py"
, line 1250, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["'17/06/2017' waarde heeft een 
ongeldige datumnotatie. Deze moet in de -MM-DD notatie opgegeven 
worden."]



The error says: "DATE" has an invalid date notation. It must be submitted 
as -MM-DD notation. Timezone/locale is Europe/Amsterdam in case that 
makes a difference.


On Tuesday, January 3, 2017 at 2:17:36 PM UTC+1, Avraham Serour wrote:
>
> please post your migration file and the error
>
> On Tue, Jan 3, 2017 at 12:00 PM, > wrote:
>
>> I recently set a default value in my local date format on a DateTimeField 
>> while I was using SQLite. The migration ran fine on my SQLite dev database, 
>> but when trying to apply the migration on my production Postgres database I 
>> got an error saying that a default value for DateTimeField must be in the 
>> format of '-MM-DD'. Wouldn't it be prudent to force users to always 
>> specify the default value in the '-MM-DD' format to avoid this problem 
>> of portability? (Not sure how MySQL handles it)
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To u

DateField default value in SQLite and Postgres

2017-01-03 Thread jorrit787
I recently set a default value in my local date format on a DateTimeField 
while I was using SQLite. The migration ran fine on my SQLite dev database, 
but when trying to apply the migration on my production Postgres database I 
got an error saying that a default value for DateTimeField must be in the 
format of '-MM-DD'. Wouldn't it be prudent to force users to always 
specify the default value in the '-MM-DD' format to avoid this problem 
of portability? (Not sure how MySQL handles it)

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4f8e0aad-9c6e-45c5-a476-22f604584b0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django.template.exceptions.TemplateSyntaxError: 'static' is not a registered tag library. Must be one of:

2016-12-29 Thread jorrit787
Have you added *django.contrib.staticfiles* to *INSTALLED_APPS* in your 
settings.py?

On Thursday, December 29, 2016 at 11:30:16 AM UTC+1, ragini dahihande wrote:
>
> Hello Guys,
> I am new to django.
> I created sample project while running it I am getting following error
>
> django.template.exceptions.TemplateSyntaxError: *'static'* is not a 
> registered tag  library. Must be one of:
>
>
>
> *following is my index.html*
> {% load static %}
>
> 
>
>
> {% if latest_question_list %}
> 
> {% for question in latest_question_list %}
> {{question.
> question_text}}
> {% endfor %}
> 
> 
> {% else %}
>  No polls are available
> {% endif %}
>
> Thanks,
> Ragini
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6b9edfd2-f1ec-4302-b4a2-92b3aa094df6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Filtering in ListView

2016-11-25 Thread jorrit787
If you're ok with using an external package you can check out django-filter 
, it makes filtering very 
easy.


On Thursday, November 24, 2016 at 8:35:30 PM UTC+1, Artem Bernatskyy wrote:
>
> Hello,
>
> how can i accomplish filtering in ListView via GET ?
>
> Now i am trying it with ListView and FormMixin...
>
> To keep long story short:
> - we are visiting page and filling form (which are generating from 
> forms.py)
> - than we are sending it via GET to the same page
> - and somehow we need to validate income data and to filter by it
>
>
> Any help is highly 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b704e15f-b422-4f31-a773-53f995946f7c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Foreign key set template

2016-09-22 Thread jorrit787
I have a question about using *model.foreignkey_set* in Django templates. I 
was trying to use *model.foreignkey_set* to determine if there were any 
foreign keys for this model, but it appears that *model.foreignkey_set* 
returns something different than *model.foreignkey_set.all* - why is that? 
Shouldn't both return *None* if there are no foreign keys?

Just curious :)

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2121cdf4-9a32-4d0e-a107-03b5e9b3fd08%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Username in password_reset_email

2016-07-09 Thread jorrit787
I want to include a reminder of a user's username in the password reset 
email, but I can't seem to include the username variable in the context. 
I'm trying to include it via the extra_email_context parameter in the URL 
pattern, but that doesn't work:

url(r'^password_reset/$', django_auth_views.password_reset, {'template_name': 
'common/password_reset_form.html',
 
'email_template_name':
 
'common/password_reset_email.html',
 
'extra_email_context': {'username': user.username},
 
'post_reset_redirect': 'common:password_reset_done'},
 
name='password_reset'),


Is there any other way to make this work?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e014d2aa-6ec6-481d-8c97-033787d1983d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password hasher for vBulletin?

2016-06-23 Thread jorrit787
As a follow-up question to this... this line gives the error "Can't convert 
'bytes' object to str implicitly":

vB_hash = hashlib.md5(hashlib.md5(force_bytes(password)).hexdigest() + 
force_bytes(salt)).hexdigest()


Do I need to insert a str() somewhere?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c722dda1-009f-4bb0-b7a7-99bd9ffb2bbc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Where is this warning coming from?

2016-06-12 Thread jorrit787
I have USE_TZ set to True.

Thanks Tim, I will try using the date lookup!

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b6a80a7d-e139-4f0c-868c-8b099830eeab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding Tinymce to Admin

2016-06-09 Thread jorrit787
Have you looked at https://github.com/aljosa/django-tinymce ?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/363caf31-2a40-4520-b53e-a2c21511bac6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Where is this warning coming from?

2016-06-09 Thread jorrit787
I have a view that calculates some quick statistics:

def index(request):
context = {
'topics_unanswered': Topic.on_site.filter(topic_type=1, 
date_published__isnull=False, reply__isnull=True).count(),
'members_unapproved': 
User.objects.filter(profile__is_approved=False).count(),
'members_unverified_7days': 
User.objects.filter(profile__is_approved=False, 
date_joined__lte=timezone.now()-timezone.timedelta(days=7), 
profile__email_verified=False).count(),
'topics_today': 
Topic.on_site.filter(date_published__gte=timezone.now().date()).count(),
'replies_today': 
Reply.on_site.filter(date_published__gte=timezone.now().date()).count(),
'members_today': 
User.objects.filter(date_joined__gte=timezone.now().date()).count(),
}
return render(request, 'admincp/index.html', context)


But when I open the page I get the following warnings:

...\lib\site-packages\django\db\models\fields\__init__.
py:1393: RuntimeWarning: DateTimeField Topic.date_published received a 
naive dat
etime (2016-06-09 00:00:00) while time zone support is active.
  RuntimeWarning)

...\lib\site-packages\django\db\models\fields\__init__.
py:1393: RuntimeWarning: DateTimeField Reply.date_published received a 
naive dat
etime (2016-06-09 00:00:00) while time zone support is active.
  RuntimeWarning)

...\lib\site-packages\django\db\models\fields\__init__.
py:1393: RuntimeWarning: DateTimeField User.date_joined received a naive 
datetim
e (2016-06-09 00:00:00) while time zone support is active.
  RuntimeWarning)

[09/Jun/2016 13:38:09] "GET /admincp/ HTTP/1.1" 200 14002

I'm using timezone(), so why am I getting these warnings?

Thanks for the help!

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/67c3251d-1785-4393-a905-1a787a2476d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


with django, how to write a grdview or table to show information and add a button or link in each row for approval?

2016-05-27 Thread jorrit787
Sounds like Formsets is what you are looking for.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71152025-51ab-4999-933b-0f608aac1045%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Integer field choice list keeps triggering migration

2016-05-02 Thread jorrit787
I have the following model and choice list:

BTW_TARIEF_CHOICES = {
(1, '6%'),
(2, '21%'),
(3, '0%'),
}


class FactuurItem(models.Model):
naam = models.CharField(max_length=100)
factuur_naam = models.CharField(max_length=100)
eenheid = models.CharField(max_length=10)
prijs = models.DecimalField(max_digits=6, decimal_places=2)
btw_tarief = models.IntegerField(choices=BTW_TARIEF_CHOICES, default=2)

class Meta:
ordering = ['naam']

def __str__(self):
return self.naam


Makemigrations creates a migration for the btw_tarief field every time I 
run it, even though the field hasn't changed. It shows up in every 
migration file that has been created since I added the field to the model. 
The only thing that seems different in every migration file is that the 
order of BTW_TARIEF_CHOICES is randomized:

class Migration(migrations.Migration):

dependencies = [
('common', '0021_auto_20160503_0849'),
]

operations = [
migrations.AlterField(
model_name='factuuritem',
name='btw_tarief',
field=models.IntegerField(choices=[(1, '6%'), (3, '0%'), (2, 
'21%')], default=2),
),
]


class Migration(migrations.Migration):

dependencies = [
('common', '0020_auto_20160502_1656'),
]

operations = [
migrations.AlterField(
model_name='factuuritem',
name='btw_tarief',
field=models.IntegerField(choices=[(2, '21%'), (3, '0%'), (1, 
'6%')], default=2),
),
]


class Migration(migrations.Migration):

dependencies = [
('common', '0019_auto_20160502_1604'),
]

operations = [
migrations.AlterField(
model_name='factuuritem',
name='btw_tarief',
field=models.IntegerField(choices=[(1, '6%'), (3, '0%'), (2, 
'21%')], default=2),
),
]


And so on... This happens on Django 1.9.5 and 1.9.6 .

Any ideas why this might be happening?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/88e66c3f-6ebe-4a14-93fe-1b865b712e61%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


What's the best way to auto convert a model field values before it is rendered?

2016-04-26 Thread jorrit787
Do you need to do actual math with the converted values, or is it just a matter 
of displaying the original value as the converted value in the template to 
those users who prefer seeing Fahrenheit? In the latter case all you would have 
to do is create a custom template tag that takes the original value and 
displays it as Fahrenheit. 

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/32a473fc-92ba-4941-ab34-a405ee4f9439%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Passing parameter to template in django while using url rendering

2016-04-25 Thread jorrit787
You should have a look at Django's Messages framework. It does what you are 
trying to achieve in a more automatic and reusable way:

https://docs.djangoproject.com/en/1.9/ref/contrib/messages/

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/884b69c6-2e5b-46ba-9dec-2501a80982e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Emails to users

2016-04-11 Thread jorrit787
Django's email features are covered here: 
https://docs.djangoproject.com/en/1.9/topics/email/ .


On Sunday, April 10, 2016 at 7:47:46 PM UTC+2, Luca Brandi wrote:
>
> Hi
> I am wondering how the admin can communicate to his users...Is there a way 
> for example to create email templates and then email them to user? 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/285fbe42-1740-40b7-9c20-3e4bb7800741%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


In a new Model with a OneToOne(User) relationship, how to get the username?

2016-04-10 Thread jorrit787
I'm not sure you can use default the way you are using on the name field, but 
in case you can: the names of the fields in User are username, firstname, and 
lastname, so you can try user.username, user.firstname or user.lastname .

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ceb10c25-a741-4c2f-a618-321bb4010328%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Trouble getting posted

2016-04-09 Thread jorrit787
Did you subscribe to the topics you posted?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9005e339-1bb1-4483-965d-78a9945aa8f3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Rendering Form Fields That Are Passed To Context Inside Of An Object

2016-04-09 Thread jorrit787
Are you sure you have the name of the fields correct? According to the 
documentation {{ form.fieldname }} should do what you want. It sounds like 
formsets would be more appropriate for what you're trying to achieve though.

And yeah, if you're going to go that specific you might as well render all 
the fields completely manually :)
 

On Saturday, April 9, 2016 at 12:21:24 AM UTC+2, David McWilliams wrote:
>
> tl:dr -- How do I explicitly render the fields in a form that's passed to 
> the context dictionary within an object?
>
> I'm building a page right now that shows a list of documents to the user. 
>  Each document has a type, a status, a list of images associated with it, 
> and finally a document update form with a few fields in it.  Because all of 
> these pieces of data belong together, I created a class to group them for 
> display (this is a simplified version for example only):
>
> class Document:
> def __init__(self, doc_type, doc_status):
> self.doc_type = doc_type
> self.doc_status = doc_status
> self.update_form = DocUpdateForm()
>
> def doc_view(request):
> # ... some other stuff to get the raw data ...
>
> documents = []
>
> for raw_doc in raw_document_data:
> documents.append(Document(raw_doc.doc_type, raw_doc.doc_status))
>
> context['documents'] = documents
>
> return render_to_response('doc_list.html', context)
>
> This all worked fine, because then in my template I was able to do 
> something nice and simple like this:
>
> ...
> Documents
> 
>   Document TypeDocument StatusUpdate
>   {% for doc in documents %}
> 
>   {{ doc.doc_type }}
>   {{ doc.doc_status }}
>   {{ doc.update_form }}
> 
>   {% endfor %}
> 
>
> Piece of cake, right?
>
> Well, now we want to change the page so that some of the form fields are 
> inside of one div, and some inside of another one so that they can be next 
> to one another instead of oriented vertically.  I consulted the Django 
> documentation here: 
> https://docs.djangoproject.com/en/1.9/topics/forms/#rendering-fields-manually 
> and 
> decided to render each of the fields myself.  This resulted in something 
> like:
>
> ...
> Documents
> 
>   Document TypeDocument StatusUpdate
>   {% for doc in documents %}
> 
>   {{ doc.doc_type }}
>   {{ doc.doc_status }}
>   {{ doc.update_form.field_1 }}
> {{ doc.update_form.field_2 }}
> 
> 
>   {% endfor %}
> 
>
>
> Unfortunately, all this does is render the text "doc.update_form.field_1" 
> instead of the form field.  It's the same behavior that I see when I 
> accidentally try to reference a key that doesn't exist in the context 
> dictionary.
>
> I can, of course, just write the form fields HTML by hand . . . but 
> goshdarnit, I'm a developer, and I want to know why the lazy way isn't 
> working.  Do I need to reference the form fields differently than the 
> documentation suggests?  Is it because I'm passing the forms to the context 
> inside of another object?  Should I be learning how to use formsets and/or 
> fieldsets?
>
> This app uses Django 1.8, in case that's important.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/094f542f-b846-407c-b953-b740c47ef64f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Suggest newsletter to integrate in django project

2016-04-09 Thread jorrit787
There's a good chance you will find something that fits your needs at 
django-packages :)

https://www.djangopackages.com/grids/g/newsletter/


On Thursday, April 7, 2016 at 12:55:08 PM UTC+2, Luca Brandi wrote:
>
> Hi,
> followed some tutorials on the web integrating Mailchimp in my django 
> project but not working...
> Any suggestion on a similar service easily to integrate in django? 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e50ea410-2f0c-4889-bfa6-709d2fa3f1c5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Should I use Django's builtin control panel for user facing purposes?

2016-04-09 Thread jorrit787
There's nothing physically stopping you from letting all your site's users 
use the Django Admin, but at least in spirit the Admin is only meant to be 
used by your staff. Even then, consider whether you need the Admin at all 
for your purposes: it sounds like what you're trying to do could easily be 
achieved with a few (generic) views you can build yourself (one for the 
client to update their info and one for your staff to review clients). Also 
consider what the Admin does: it's focused on managing data (like adding 
blog posts to a blog, or recipes to a recipe website). What you're trying 
to do is more procedure-focused (manipulating already-existing data in 
several ways). Custom views may be more suited to that purpose.


On Friday, April 8, 2016 at 5:24:00 PM UTC+2, Andrew Chiw wrote:
>
> I'm making a Django website for a company, where the company's employees 
> will validate clients that sign up.
> I'm thinking that the clients should have a mini control panel where they 
> can change their own information only, while the company's employees have 
> their own control panel where they can manage the clients and set whether 
> or not they can change their information anymore, etc.
> Should I / Can I use the built in Django control panel for this purpose?
> If not, is django-user-accounts what I'm looking for?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1cd1cce2-52eb-488c-bb59-874c281c5127%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: inventory in Django

2016-04-09 Thread jorrit787
Have you looked into Django ecommerce packages that are already out there? 
They may fit most of your needs, and you could extend them where they don't.

https://www.djangopackages.com/grids/g/ecommerce/

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3703c43c-fab2-490c-bf0d-2c726acfebd8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to know which models have changed and need make migrations?

2016-04-09 Thread jorrit787
I've run into the problem of migration files not being added to source 
control with PyCharm because PyCharm doesn't seem to automatically commit 
auto-created files unless you explicitly tell it to in the settings (and 
even then it doesn't always work).

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56c2a5e2-af13-44d5-82b6-db769c2c5861%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with dumpdata/loaddata

2016-04-09 Thread jorrit787
I jus tested it again and it happens even without opening the file in an 
editor first. Would that be a bug then?


On Friday, April 8, 2016 at 10:23:43 AM UTC+2, Ramiro Morales wrote:
>
> It shouldn't. Are you sure you haven't opened and saved the json file with 
> a text editor that might be adding the BOM, e.g. Notepad before running 
> loaddata?
> On Apr 7, 2016 9:17 PM, > wrote:
>
>> Opening the JSON file in Notepad++ certainly gives some insight... It 
>> says it's encoded in USC-2 LE BOM. Converting it to UTF-8 with BOM in 
>> Notepad++ solves the problem.
>>
>> Question though, why does dumpdata create files with an encoding that can 
>> not be used out of the box with loaddata?
>>
>> -- 
>> 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 https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/b3f4fbbf-bcad-4376-8ed1-aa476b8c8a88%40googlegroups.com
>>  
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/313e069c-c719-42e6-9292-cf5bf9ab901d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with dumpdata/loaddata

2016-04-07 Thread jorrit787
Opening the JSON file in Notepad++ certainly gives some insight... It says 
it's encoded in USC-2 LE BOM. Converting it to UTF-8 with BOM in Notepad++ 
solves the problem.

Question though, why does dumpdata create files with an encoding that can 
not be used out of the box with loaddata?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b3f4fbbf-bcad-4376-8ed1-aa476b8c8a88%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Problems with dumpdata/loaddata

2016-04-06 Thread jorrit787
Thank you for the replies. *members* and *posts* are the names of my apps.

The first line of the XML file when I open it in Notepad says:



The JSON file has no distinguishable first line, it just starts right away 
with the data.


On Wednesday, April 6, 2016 at 1:45:44 AM UTC+2, jorr...@gmail.com wrote:
>
> I want to dump and load data for two apps that I have. Using dumpdata 
> works fine:
>
> python manage.py dumpdata members posts > data.json
>
> or
>
> python manage.py dumpdata members posts --format=xml > data.xml
>
> However, when I try to load the same data back with loaddata I get the 
> following errors:
>
> With JSON:
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
> line 353, in ex
> utility.execute()
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
> line 345, in ex
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "C:\Python27\lib\site-packages\django\core\management\base.py", 
> line 348, in run_fr
> self.execute(*args, **cmd_options)
>   File "C:\Python27\lib\site-packages\django\core\management\base.py", 
> line 399, in execut
> output = self.handle(*args, **options)
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py"
> , line 6
> self.loaddata(fixture_labels)
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py"
> , line 1
> self.load_label(fixture_label)
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py"
> , line 1
> for obj in objects:
>   File "C:\Python27\lib\site-packages\django\core\serializers\json.py", 
> line 76, in Deseri
> stream_or_string = stream_or_string.decode('utf-8')
>   File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
> return codecs.utf_8_decode(input, errors, True)
> UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: 
> invalid start byte
>
>
>
> With XML:
> Traceback (most recent call last):
>   File "manage.py", line 10, in 
> execute_from_command_line(sys.argv)
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
> line 353, in execute_from_comman
> utility.execute()
>   File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
> line 345, in execute
> self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "C:\Python27\lib\site-packages\django\core\management\base.py", 
> line 348, in run_from_argv
> self.execute(*args, **cmd_options)
>   File "C:\Python27\lib\site-packages\django\core\management\base.py", 
> line 399, in execute
> output = self.handle(*args, **options)
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py"
> , line 60, in handle
> self.loaddata(fixture_labels)
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py"
> , line 100, in loaddata
> self.load_label(fixture_label)
>   File 
> "C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py"
> , line 152, in load_label
> for obj in objects:
>   File "C:\Python27\lib\site-packages\django\utils\six.py", line 558, in 
> next
> return type(self).__next__(self)
>   File 
> "C:\Python27\lib\site-packages\django\core\serializers\xml_serializer.py", 
> line 174, in __next__
> for event, node in self.event_stream:
>   File "C:\Python27\lib\xml\dom\pulldom.py", line 232, in next
> rc = self.getEvent()
>   File "C:\Python27\lib\xml\dom\pulldom.py", line 265, in getEvent
> self.parser.feed(buf)
>   File "C:\Python27\lib\xml\sax\expatreader.py", line 217, in feed
> self._err_handler.fatalError(exc)
>   File "C:\Python27\lib\xml\sax\handler.py", line 38, in fatalError
> raise exception
> xml.sax._exceptions.SAXParseException: :1:31: encoding specified 
> in XML declaration is incorrect
>
> What gives?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/56a3a584-8052-4c80-bba9-35c4ae55cb96%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Architecture of multiple Sites

2016-04-05 Thread jorrit787
These are both interesting solutions. I will give them a try, thanks!


On Tuesday, March 22, 2016 at 2:08:27 AM UTC+1, jorr...@gmail.com wrote:
>
> I'm wondering if I understand the Sites framework correctly... I'm 
> building a forum-like project which will initially be accessible from 
> mydomain.com . The project contains several apps like posts, members, 
> ads, etc. Eventually I would like to create myseconddomain.com, which 
> would have unique posts, but share the members, ads, etc. apps and look the 
> same as the first site except for the domain name and title in the header. 
> The code will be identical to the first site. Can I achieve this with a 
> single project and several SITE_IDs, or am I correct in thinking that the 
> Sites framework is only for sharing the same database across projects, and 
> not the code files? And if there is a way to share the code files, how do 
> you get around the fact that you set SITE_ID once in settings.py?
>
> Thanks in advance for the help!
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/96a2bd86-2470-4bcc-9d54-f9c65fcdae9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Problems with dumpdata/loaddata

2016-04-05 Thread jorrit787
I want to dump and load data for two apps that I have. Using dumpdata works 
fine:

python manage.py dumpdata members posts > data.json

or

python manage.py dumpdata members posts --format=xml > data.xml

However, when I try to load the same data back with loaddata I get the 
following errors:

With JSON:
Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 353, in ex
utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 345, in ex
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 
348, in run_fr
self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 
399, in execut
output = self.handle(*args, **options)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", 
line 6
self.loaddata(fixture_labels)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", 
line 1
self.load_label(fixture_label)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", 
line 1
for obj in objects:
  File "C:\Python27\lib\site-packages\django\core\serializers\json.py", 
line 76, in Deseri
stream_or_string = stream_or_string.decode('utf-8')
  File "C:\Python27\lib\encodings\utf_8.py", line 16, in decode
return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: 
invalid start byte



With XML:
Traceback (most recent call last):
  File "manage.py", line 10, in 
execute_from_command_line(sys.argv)
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 353, in execute_from_comman
utility.execute()
  File "C:\Python27\lib\site-packages\django\core\management\__init__.py", 
line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 
348, in run_from_argv
self.execute(*args, **cmd_options)
  File "C:\Python27\lib\site-packages\django\core\management\base.py", line 
399, in execute
output = self.handle(*args, **options)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", 
line 60, in handle
self.loaddata(fixture_labels)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", 
line 100, in loaddata
self.load_label(fixture_label)
  File 
"C:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", 
line 152, in load_label
for obj in objects:
  File "C:\Python27\lib\site-packages\django\utils\six.py", line 558, in 
next
return type(self).__next__(self)
  File 
"C:\Python27\lib\site-packages\django\core\serializers\xml_serializer.py", 
line 174, in __next__
for event, node in self.event_stream:
  File "C:\Python27\lib\xml\dom\pulldom.py", line 232, in next
rc = self.getEvent()
  File "C:\Python27\lib\xml\dom\pulldom.py", line 265, in getEvent
self.parser.feed(buf)
  File "C:\Python27\lib\xml\sax\expatreader.py", line 217, in feed
self._err_handler.fatalError(exc)
  File "C:\Python27\lib\xml\sax\handler.py", line 38, in fatalError
raise exception
xml.sax._exceptions.SAXParseException: :1:31: encoding specified in 
XML declaration is incorrect

What gives?

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dc3c9375-a180-45cb-b718-f272181575be%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django tutorial part 3 - question_id vs question.id

2016-03-26 Thread jorrit787
I believe Django lets you access the pk field of a table (which is created 
automatically unless you define it explicitly on your model) in multiple ways: 
self.pk, self.id, and self._id. Someone correct me if I'm wrong.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/53611858-55d3-4159-9f76-118af5b919df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: get email address of the user in views

2016-03-22 Thread jorrit787
You should be able to use *request.user.email*, assuming you have the 
*django.contrib.auth* app installed and the user is logged in.


On Tuesday, March 22, 2016 at 1:33:39 PM UTC+1, Vasu Dev Garg wrote:
>
> I want to get the email address of the user which i filter in views 
> function. How to get it?
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1cc4972f-f1f3-4bb0-9181-187f382ab1eb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Architecture of multiple Sites

2016-03-22 Thread jorrit787
But if I don't set the SITE_ID in settings.py I can't use the 
CurrentSiteManager, correct?


On Tuesday, March 22, 2016 at 1:33:39 PM UTC+1, Sai Kiran wrote:
>
> If you need to use single projects for more than domains, create an entry 
> in django_site model by giving domain as well as verbose name. Don't give 
> any SITE_ID in settings.py, instead of this you can use 
> Site.objects.get_current() in your view and compare the domain names and 
> change the header accordingly.
>
> Please feel free to correct me if I'm wrong.
>
>
> On Tuesday, March 22, 2016 at 6:38:27 AM UTC+5:30, jorr...@gmail.com 
> wrote:
>>
>> I'm wondering if I understand the Sites framework correctly... I'm 
>> building a forum-like project which will initially be accessible from 
>> mydomain.com . The project contains several apps like posts, members, 
>> ads, etc. Eventually I would like to create myseconddomain.com, which 
>> would have unique posts, but share the members, ads, etc. apps and look the 
>> same as the first site except for the domain name and title in the header. 
>> The code will be identical to the first site. Can I achieve this with a 
>> single project and several SITE_IDs, or am I correct in thinking that the 
>> Sites framework is only for sharing the same database across projects, and 
>> not the code files? And if there is a way to share the code files, how do 
>> you get around the fact that you set SITE_ID once in settings.py?
>>
>> Thanks in advance for the help!
>>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/efe8db78-129f-4d55-a891-626b209450a8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Architecture of multiple Sites

2016-03-21 Thread jorrit787
I'm wondering if I understand the Sites framework correctly... I'm building 
a forum-like project which will initially be accessible from mydomain.com . 
The project contains several apps like posts, members, ads, etc. Eventually 
I would like to create myseconddomain.com, which would have unique posts, 
but share the members, ads, etc. apps and look the same as the first site 
except for the domain name and title in the header. The code will be 
identical to the first site. Can I achieve this with a single project and 
several SITE_IDs, or am I correct in thinking that the Sites framework is 
only for sharing the same database across projects, and not the code files? 
And if there is a way to share the code files, how do you get around the 
fact that you set SITE_ID once in settings.py?

Thanks in advance for the help!

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/86d91419-1f66-48ef-a936-b43ac12699ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Unable to parse connection string: "" when using django cache

2016-03-19 Thread jorrit787
As an aside, it looks like you're including CommonMiddleware twice.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/80e6b310-d6ae-46d2-9268-13006125b248%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password hasher for vBulletin?

2016-03-19 Thread jorrit787
Thanks for the help!

If anyone looks at this in the future, this is the code I ended up using:

*hashers.py*

class PBKDF2WrappedvBPasswordHasher(PBKDF2PasswordHasher):
algorithm = 'pbkdf2_vB'

def encode_vB_hash(self, vB_hash, salt, iterations=None):
return super(PBKDF2WrappedvBPasswordHasher, self).encode(vB_hash, salt, 
iterations)

def encode(self, password, salt, iterations=None):
vB_hash = hashlib.md5(hashlib.md5(force_bytes(password)).hexdigest() + 
force_bytes(salt)).hexdigest()
return self.encode_vB_hash(vB_hash, salt, iterations)


*settings.py*

PASSWORD_HASHERS = [
'django.contrib.auth.hashers.PBKDF2PasswordHasher',
'members.hashers.PBKDF2WrappedvBPasswordHasher',
]


Importing vBulletin password in the Django format, assuming 2 columns for 
vBulletin containing salt and MD5 hash, respectively:

password='pbkdf2_vB' + '$' + row[5] + '$' + row[6],


Upgrading to pbkdf2_vB hash:

hasher = PBKDF2WrappedvBPasswordHasher()
algorithm, salt, vB_hash = user.password.split('$', 2)
user.password = hasher.encode_vB_hash(vB_hash, salt)



On Wednesday, March 16, 2016 at 12:54:18 AM UTC+1, Tim Graham wrote:
>
> I can't think of anything offhand besides implementing your own 
> PBKDF2PasswordHasher subclass which does its own more sophisticated 
> splitting that doesn't get confused by dollar signs in the salt.
>
> On Tuesday, March 15, 2016 at 7:26:59 PM UTC-4, jorr...@gmail.com wrote:
>>
>> Holy crap, you guys have really thought of everything! Love it!
>>
>> Unfortunately this doesn't work on all users because some salts contain 
>> the *$* character which gives the *assert salt and '$' not in salt* 
>> error. Is there a workaround for this?
>>
>>
>> On Tuesday, March 15, 2016 at 4:59:39 PM UTC+1, Tim Graham wrote:
>>>
>>> Take a look at 
>>> https://docs.djangoproject.com/en/stable/topics/auth/passwords/#password-upgrading-without-requiring-a-login
>>>
>>> Instead of SHA1PasswordHasher().encode() you'll want to use vBulletin's 
>>> hashing algorithm.
>>>
>>> On Tuesday, March 15, 2016 at 11:54:32 AM UTC-4, jorr...@gmail.com 
>>> wrote:

 I'm converting an old vBulletin 3.8 installation to a Django web app 
 and I'm wondering if I can migrate users over with their passwords intact.

 vBulletin uses *md5(md5(password) + salt)* to hash its passwords, 
 would any of Django's built-in password hashers work with this out of the 
 box?

 Some of the salts also contain the *$* character, I'm guessing that's 
 a big problem?

 I'm wondering if it would be easiest (or even possible) to write a 
 custom password hasher for this or just have everyone reset their 
 passwords 
 once the new site goes live.

 Any thoughts on this would be 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e6be910c-f01f-471e-a262-53caf749c124%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Documentation for User.set_unusable_password() doesn't feel complete

2016-03-15 Thread jorrit787
Does setting an unusable password on a user prevent them from using the 
reset password feature?


On Wednesday, January 13, 2016 at 10:14:11 PM UTC+1, Brice PARENT wrote:
>
> When you set an usable password (using 
> https://docs.djangoproject.com/en/dev/ref/contrib/auth/#django.contrib.auth.models.User.set_unusable_password),
>  
> it is not really clear that to make the password usable again, one should 
> use `set_password` and define a new one. 
> The doc says that this method "Marks the user as having no password set." 
> which sounds like it's a boolean attribute somewhere that we might unset 
> somehow. It should probably state that the method replaces the active 
> password by one that can never be used, and add that to be able to use the 
> password, it has to be set again using `set_password`. It also gives the 
> false impression that we could prevent temporarily an user from login by 
> setting this, but that would be a bad idea as it would lose the password.
>
> Or maybe the method name `set_unusable_password` is explicit enough in 
> english, but for other languages, I'm not sure the documentation should 
> only rely on the methods names to be understood (the description looks like 
> the one for a method that would be called `set_password_unusable`).
>
> What do you think about it?
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7823e5fc-e7fe-4059-a1ad-cafbda1c2351%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Password hasher for vBulletin?

2016-03-15 Thread jorrit787
Holy crap, you guys have really thought of everything! Love it!

Unfortunately this doesn't work on all users because some salts contain the 
*$* character which gives the *assert salt and '$' not in salt* error. Is 
there a workaround for this?


On Tuesday, March 15, 2016 at 4:59:39 PM UTC+1, Tim Graham wrote:
>
> Take a look at 
> https://docs.djangoproject.com/en/stable/topics/auth/passwords/#password-upgrading-without-requiring-a-login
>
> Instead of SHA1PasswordHasher().encode() you'll want to use vBulletin's 
> hashing algorithm.
>
> On Tuesday, March 15, 2016 at 11:54:32 AM UTC-4, jorr...@gmail.com wrote:
>>
>> I'm converting an old vBulletin 3.8 installation to a Django web app and 
>> I'm wondering if I can migrate users over with their passwords intact.
>>
>> vBulletin uses *md5(md5(password) + salt)* to hash its passwords, would 
>> any of Django's built-in password hashers work with this out of the box?
>>
>> Some of the salts also contain the *$* character, I'm guessing that's a 
>> big problem?
>>
>> I'm wondering if it would be easiest (or even possible) to write a custom 
>> password hasher for this or just have everyone reset their passwords once 
>> the new site goes live.
>>
>> Any thoughts on this would be 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9e50689-3286-4cf3-84cb-367bd72fadbe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Password hasher for vBulletin?

2016-03-15 Thread jorrit787
I'm converting an old vBulletin 3.8 installation to a Django web app and 
I'm wondering if I can migrate users over with their passwords intact.

vBulletin uses *md5(md5(password) + salt)* to hash its passwords, would any 
of Django's built-in password hashers work with this out of the box?

Some of the salts also contain the *$* character, I'm guessing that's a big 
problem?

I'm wondering if it would be easiest (or even possible) to write a custom 
password hasher for this or just have everyone reset their passwords once 
the new site goes live.

Any thoughts on this would be 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2c960ff9-038d-4ed8-9937-1ff07869bc81%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: RegExp problems

2016-03-09 Thread jorrit787
Your improvements work great, thank you. And thank you for the very 
detailed explanations!

On Tuesday, March 8, 2016 at 9:41:11 AM UTC+1, Michal Petrucha wrote:
>
> On Mon, Mar 07, 2016 at 05:44:08PM -0800, jorr...@gmail.com  
> wrote: 
> > I'm trying to replace *[URL]www.link.com[/URL]* with HTML with this 
> regexp: 
> > 
> > topic.text = re.sub("(\[URL\])(.*)(\[\/URL\])", '$2', 
> topic 
> > .text, flags=re.I) 
> > 
> > But it's giving me the following problems: 
> > 
> >1. The $2 capture group is only able to be repeated once, so I get 
> >$2 
> >instead of 
> >www.link.com 
>
> I have my doubts – if you use the standard Python re library, then the 
> way to refer to captured groups is "\1", "\2", etc., not "$1". When I 
> try the code you posted above, I get the following result (i.e., not 
> even the first occurrence of "$2" gets substituted):: 
>
> >>> re.sub("(\[URL\])(.*)(\[\/URL\])", '$2', '[URL]
> www.link.com[/URL]', flags=re.I) 
> '$2' 
>
> In order to make the substitution work for a single occurrence of 
> [URL]...[/URL], you can use the following, which uses "\2" (Also, when 
> writing regular expressions, or other strings that are supposed to 
> contain the backslash character, it is a good idea to write them as 
> raw string literals, i.e. prefix them with a "r", which I've done 
> below; that way, Python won't try to interpret the backslashes as 
> special characters – otherwise, "\2" would become a character with an 
> ASCII value of 2):: 
>
> >>> re.sub(r"(\[URL\])(.*)(\[\/URL\])", r'\2', '[URL]
> www.link.com[/URL]', flags=re.I) 
> 'www.link.com' 
>
> >2. Only the first *[URL]* is matched. Everything after the first 
> *[/URL]* 
> >is simply deleted... 
>
> The solution above gets you halfway there – re.sub will replace all 
> matches by default, the problem here is that the "(.*)" part of your 
> regex will matches everything between the first "[URL]", and the last 
> "[/URL]":: 
>
> >>> re.sub(r"(\[URL\])(.*)(\[\/URL\])", r'\2', '[URL]
> www.link1.com[/URL][URL]www.link2.com[/URL][URL]www.link3.com[/URL]', 
> flags=re.I) 
> 'www.link1.com[/URL][URL]www.link2.com[/URL][URL]
> www.link3.com' 
>
> The reason is that the asterisk operator in a regex is greedy, which 
> means a ".*" will try to match as much as possible. When you use the 
> non-greedy version of the operator (which you get by putting a 
> question mark after the asterisk), you get the result you want:: 
>
> >>> re.sub(r"(\[URL\])(.*?)(\[\/URL\])", r'\2', '[URL]
> www.link1.com[/URL][URL]www.link2.com[/URL][URL]www.link3.com[/URL]', 
> flags=re.I) 
> 'www.link1.com
> www.link2.comwww.link3.com' 
>
>
> You can read an explanation of the difference between greedy and 
> non-greedy regular expressions in the Python docs: 
> https://docs.python.org/2/howto/regex.html#greedy-versus-non-greedy 
>
> Good luck, 
>
> Michal 
>
> > 
> > I hope someone can help me with this. I'm using Python 2.7 if it makes a 
> > difference. 
> > 
> > -- 
> > 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 https://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/fce5a726-8a4c-455a-a978-6ee70d66464e%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6d3e0a68-ec36-4a7a-bcb5-c57a775e8e59%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


RegExp problems

2016-03-07 Thread jorrit787
I'm trying to replace *[URL]www.link.com[/URL]* with HTML with this regexp:

topic.text = re.sub("(\[URL\])(.*)(\[\/URL\])", '$2', topic
.text, flags=re.I)

But it's giving me the following problems:

   1. The $2 capture group is only able to be repeated once, so I get 
   $2
   instead of 
   www.link.com
   2. Only the first *[URL]* is matched. Everything after the first *[/URL]* 
   is simply deleted...
   
I hope someone can help me with this. I'm using Python 2.7 if it makes a 
difference.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fce5a726-8a4c-455a-a978-6ee70d66464e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error running Django tutorial

2016-03-02 Thread jorrit787
Glad you got it solved!!


On Monday, February 29, 2016 at 10:10:58 PM UTC+1, Mike Kipling wrote:
>
> I found the problem.
>
> When the mysite\urls.py file is created, it has this line already in it.
>
> from django.conf.urls import url
>
> The tutorial asks you to add the following lines to the file.
>
> from django.conf.urls import include, url
> from django.contrib import admin
>
> urlpatterns = [
> url(r'^polls/', include('polls.urls')),
> url(r'^admin/', admin.site.urls),
> ]
>
> I must did not notice that the 'include' was different, and so I had not 
> placed it into the file.  I changed the file to add the 'include' and 
> everything worked.
>
> Thank you for the help.
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4ce4dd13-aa8b-4981-8a0a-727a16ac19ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error running Django tutorial

2016-02-29 Thread jorrit787
Can you attach your entire project's code in a ZIP file? I'm curious to 
test this myself...


On Monday, February 29, 2016 at 9:23:20 PM UTC+1, Mike Kipling wrote:
>
> I added polls to settings.py :
> INSTALLED_APPS = [
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> 'polls.apps.PollsConfig',
> ]
>
> Then I tried the migration:
> C:\Data\Django_Code\FirstApp\mysite>python manage.py migrate
> Operations to perform:
>   Apply all migrations: admin, sessions, contenttypes, auth
> Running migrations:
>   No migrations to apply.
>
> Then I started the server and tried going to the address, but got the same 
> results:
> C:\Data\Django_Code\FirstApp\mysite>python manage.py runserver
> Performing system checks...
>
> System check identified no issues (0 silenced).
> February 29, 2016 - 14:16:37
> Django version 1.9.2, using settings 'mysite.settings'
> Starting development server at http://127.0.0.1:8000/
> Quit the server with CTRL-BREAK.
> Not Found: /polls/
> [29/Feb/2016 14:16:46] "GET /polls/ HTTP/1.1" 404 1921
>
> I am working on a Windows OS, so I thought that perhaps changing the '/' 
> in the mysite\urls.py to '\\' might help, but it did not.
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bc913fc7-fe00-427f-87c7-cd5d52783551%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error running Django tutorial

2016-02-29 Thread jorrit787
Well that's strange... The problem appears to be that your polls.urls file 
is not getting included in your project's URLConf (since the error message 
in your first post says that the only URL tried was *admin/* ). I'm not 
sure if adding the app to INSTALLED_APPS is necessary for an app's URLConf 
to be able to be included, but it's worth a try. In FirstApp/settings.py 
add 'polls' to the list of INSTALLED_APPS so that it looks something like 
this:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'polls.apps.PollsConfig',
]



Otherwise it does seem like it could be a file refresh problem.


On Monday, February 29, 2016 at 4:03:42 PM UTC+1, Mike Kipling wrote:
>
> Jorr,
>
> No, I did not modify the settings.py file, because the tutorial 
> specifically states: 
>
> Note
>
> Ignore the warning about unapplied database migrations for now; we’ll deal 
> with the database shortly.
>
>
> Here is a link to the tutorial: 
> https://docs.djangoproject.com/en/1.9/intro/tutorial01/
>
>
>
>
>
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d00ca4a7-856e-4045-bc99-7b03c037b46f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Error running Django tutorial

2016-02-29 Thread jorrit787
Did you add 'polls' to your list of INSTALLED_APPS in your settings.py? After 
that you should run > python manage.py migrate like the terminal is suggesting 
to you.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b4f497cd-4653-47ae-a935-33358b3a7569%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Home Page

2016-02-23 Thread jorrit787
I struggled with this as well. I usually end up creating a 'common' app for my 
homepage and project-wide templates and static files, but I don't know if 
that's considered a best practice. Alternatively you could put your homepage in 
your most used/most important app.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/94c2253b-3343-436a-a7c2-606d2358579c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: context dictionary

2016-02-23 Thread jorrit787
Wouldn't including the name 'user' in your context dictionary override the 
authenticated user object in your template? Might make for some unexpected 
behavior.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/5e3a7134-d7a6-4385-863f-c25437922127%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django: drop down menu not displaying on template despite correct syntax

2016-02-17 Thread jorrit787
Have you tried using just {{ form }} instead of {{ form.mismatch }} ?

Also, (not sure if this is related) in your MISMATCH_CHOICES tuple you are 
giving strings instead of integers for the key value. Try using (0, '0') 
instead of ('0','0')


On Tuesday, February 16, 2016 at 2:16:17 PM UTC+1, clarkso...@gmail.com 
wrote:
>
> I have successfully configured a way to upload files to a website that I 
> am making. However we would like to include a drop-down menu on the site. 
> However, we want to include in the form of a drop-down menu called 
> "mismatch choice":
>
>
> models.py: for drop-down menu
>
>  class Mismatches(models.Model):
>
>   MISMATCH_CHOICES = (
>
>('0', '0'),
>
>('1', '1'),
>
>('2', '2'),
>
>('3', '3'),
>
>)
>
>   mismatch = models.IntegerField(max_length=1, default='0', 
> choices = MISMATCH_CHOICES)
>
>
> forms.py for drop-down menu:
>
>   class MismatchesForm(ModelForm): #unsure how to reference a 
> class in our in-app-urls.py
>
> class Meta:
>
> model = Mismatches
>
> fields = ['mismatch']
>
> 'model=Mismatches' links to the Mismatches class in models and the 'field' 
> gives the options.
>
>
> views.py for drop-down menu
>
>  class Mismatch_Choice(FormView):
>
>template_name = 'list.html'
>
>form_class = MismatchesForm
>
>
>
> "template_name = 'list.html'" links the html page called list.html. 
> 'form_class' links to the form 'MismatchesForm'.
>
> html for drop-down menu
>
> {% csrf_token %}
>
>   {{ form.mismatch }}
>
>   
>
> 
>
>
> We used a tutorial as a template for our code but it won't display on our 
> html page even though we have referenced it with {{ form.mismatch}} which 
> links to the variable 'mismatch' which is set in our form as the 'model' 
> and hence links to the options given in models.py. 
>
> We are wondering if the html page is not seeing the drop-down menu because 
> it's set as a class in the forms.py but we haven't referenced a class in 
> our in-app urls.py (is there a way to do this?)...
>
> NOTE: all migrations were accordingly applied and the server was restarted 
> multiple times
>

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/dab775e8-7d3a-4140-b9ed-f4b16cef8b35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Multiple User Login

2016-02-11 Thread jorrit787
I'm just being curious here but in what scenario would you have multiple 
people logging in at the same time using the same computer/browser?


On Thursday, February 11, 2016 at 1:30:21 PM UTC+1, Aakash Tewari wrote:
>
> Hello
>
>
> Here is new one I guess. 
>
> We have 3 types of users say A, B, C. All have 3 different login pages on 
> same domain. We have extended User model by OneToOne relationship like this
>
> class AModel(models.Model):
> users = models.OneToOneField(User, on_delete=models.CASCADE)
> is_A = models.NullBooleanField(default=False)
>
> class BModel(models.Model):
> users = models.OneToOneField(User, on_delete=models.CASCADE)
> is_B = models.NullBooleanField(default=False)
>
>
> class BModel(models.Model):
> users = models.OneToOneField(User, on_delete=models.CASCADE)
> is_B = models.NullBooleanField(default=False)
>
>
> Now During login we check like this :
>
> username=request.POST.get('username','')
> password=request.POST.get('pass','')
> user = authenticate(username=username, password=password)
> u = AModel.objects.get(users=user)
> if user is not None:
>if user.is_active and u.isA:
>   login(request, user)
>   return HttpResponseRedirect("/home/")
>
> same way for B and C
>
>
>
> Now issue is when A login session is set and everything works fine, but when 
> user B logins, session for user A is removed. 
>
> How can we allow 3 user 3 tabs 3 diff(login and home page)  on same browser
>
>
> 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/064e44d3-c541-470d-91de-c481faf3a7c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Access dynamic session variable name in template

2015-07-02 Thread jorrit787
This doesn't seem to work :(

def comment_upvote(request, comment_id):
comment = get_object_or_404(Comment.objects.filter(id__exact=comment_id,
approved=True))
votes = request.session.setdefault('commentvotes', {})
if comment.id not in votes:
comment.upvotes = comment.upvotes + 1
comment.votes = comment.votes + 1
comment.save()
votes[comment.id] = True
else:
messages.error(request, 'You have already voted on this comment.')
return redirect('comments')

{% if comment.id not in 
request.session.commentvotes 
%}






{% endif %}

With this code the first time that someone loads the comments page (fresh 
session) no buttons show up at all (I guess because the session key is not 
set?). And it also doesn't prevent voting on the same comment twice.


On Thursday, July 2, 2015 at 8:41:48 PM UTC+2, Daniel Roseman wrote:
>
> On Thursday, 2 July 2015 19:09:59 UTC+1, jorr...@gmail.com wrote:
>>
>> Hi everyone,
>>
>> I am trying to keep track of who has voted on a comment by setting 
>> session variables like 'commentvote1', 'commentvote2', etc to True. These 
>> variable names are dynamically generated based on the id of the comment. 
>> How can I access these dynamic variables in my template? I've tried this 
>> but it doesn't seem to work:
>>
>> views.py
>>
>> def comment_upvote(request, comment_id):
>> comment = get_object_or_404(Comment.objects.filter(id__exact=
>> comment_id,approved=True))
>> if 'commentvote' + str(comment.id) not in request.session:
>> comment.upvotes = comment.upvotes + 1
>> comment.votes = comment.votes + 1
>> comment.save()
>> request.session['commentvote' + str(comment.id)] = True
>> else:
>> messages.error(request, 'You have already voted on this comment.'
>> )
>> return redirect('comments')
>>
>> The logic in the view is confirmed to work - It won't let you vote on the 
>> same comment twice.
>>
>> template
>>
>> {% with 'commentvote'|add:comment.id as voted %}
>> {% if not request.session.voted %}
>> > onclick="javascript:document.location.href='{% url 'comment_upvote' 
>> comment.id %}';">
>> 
>> 
>> > onclick="javascript:document.location.href='{% url 'comment_downvote' 
>> comment.id %}';">
>>  > span>
>> 
>> {% endif %}
>> {% endwith %}
>>
>> Any help would be appreciated!
>>
>
>
> I think you have the wrong data structure. Instead of storing all the 
> comment votes as separate keys in the session,  consider storing them in a 
> single "commentvotes" dictionary:
>
> votes = request.session.setdefault('commentvotes', {})
> if comment.id not in votes:
> ...
> votes[comment.id] = True
> else:
> ...
>
> and the template:
>
> {% if comment.id not in request.session.votes %}
>
> --
> Daniel.
>

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f71917bf-05a2-4a02-920d-1a07dd23fe0d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Access dynamic session variable name in template

2015-07-02 Thread jorrit787
Hi everyone,

I am trying to keep track of who has voted on a comment by setting session 
variables like 'commentvote1', 'commentvote2', etc to True. These variable 
names are dynamically generated based on the id of the comment. How can I 
access these dynamic variables in my template? I've tried this but it 
doesn't seem to work:

views.py

def comment_upvote(request, comment_id):
comment = get_object_or_404(Comment.objects.filter(id__exact=comment_id,
approved=True))
if 'commentvote' + str(comment.id) not in request.session:
comment.upvotes = comment.upvotes + 1
comment.votes = comment.votes + 1
comment.save()
request.session['commentvote' + str(comment.id)] = True
else:
messages.error(request, 'You have already voted on this comment.')
return redirect('comments')

The logic in the view is confirmed to work - It won't let you vote on the 
same comment twice.

template

{% with 'commentvote'|add:comment.id as voted %}
{% if not request.session.voted %}




 

{% endif %}
{% endwith %}

Any help would be 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6409d0b4-ac59-4054-95ef-f3a018554148%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Inconsistency when importing views and models

2015-06-20 Thread jorrit787
Thank you for the very detailed explanations everyone!


On Saturday, June 20, 2015 at 3:11:34 AM UTC+2, jorr...@gmail.com wrote:
>
> This is mostly a cosmetic question, and I could be completely wrong 
> because I'm fairly new to Django, or it could be that there is a perfectly 
> logical explanation for this, but here goes:
>
> It seems the code required to import views in urls.py and models in 
> views.py is inconsistent (and in the case of urls.py perhaps redudant). 
>
> To import views in urls.py I have to use
>
> from  import views
>
> ...while in views.py I can simply write
>
> from models import *
>
> Why do I need to reference the appname in urls.py but not in views.py? Or 
> is there a reason for 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/7c0f2244-862e-415c-be4a-d5e9120e36f2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Inconsistency when importing views and models

2015-06-19 Thread jorrit787
This is mostly a cosmetic question, and I could be completely wrong because 
I'm fairly new to Django, or it could be that there is a perfectly logical 
explanation for this, but here goes:

It seems the code required to import views in urls.py and models in 
views.py is inconsistent (and in the case of urls.py perhaps redudant). 

To import views in urls.py I have to use

from  import views

...while in views.py I can simply write

from models import *

Why do I need to reference the appname in urls.py but not in views.py? Or 
is there a reason for 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/03eb4740-6503-4757-ae09-9183ac2b8502%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.