Django-cms KeyError at /en/cms_wizard/create/

2017-07-26 Thread IaMtheMcee
Hi, I'm getting this error when i try to create a new page. here's the 
traceback.. any ideas on how to fix this?

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/en/cms_wizard/create/?language=en

Django Version: 1.11.3
Python Version: 3.6.0
Installed Applications:
('djangocms_admin_style',
 'django.contrib.auth',
 'django.contrib.contenttypes'
,
 'django.contrib.sessions',
 'django.contrib.admin',
 'django.contrib.sites',
 'django.contrib.sitemaps',
 'django.contrib.staticfiles',
 'django.contrib.messages',
 'cms',
 'menus',
 'sekizai',
 'treebeard',
 'djangocms_text_ckeditor',
 'filer',
 'easy_thumbnails',
 'djangocms_column',
 'djangocms_link',
 'cmsplugin_filer_file',
 'cmsplugin_filer_folder',
 'cmsplugin_filer_image',
 'cmsplugin_filer_utils',
 'djangocms_style',
 'djangocms_snippet',
 'djangocms_googlemap',
 'djangocms_video',
 'mysite')
Installed Middleware:
('cms.middleware.utils.ApphookReloadMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware',
 'cms.middleware.language.LanguageCookieMiddleware')


Template error:
In template 
C:\Users\Alexander\Desktop\v1\lib\site-packages\django\contrib\admin\templates\admin\base.html,
 
error at line 0
  1 : {% load i18n static %}
   2 : {% get_current_language as LANGUAGE_CODE %}{% 
get_current_language_bidi as LANGUAGE_BIDI %}
   3 : 
   4 : 
   5 : {% block title %}{% endblock %}
   6 : 
   7 : {% block extrastyle %}{% endblock %}
   8 : {% if LANGUAGE_BIDI %}{% endif %}
   9 : {% block extrahead %}{% endblock %}
   10 : {% block blockbots %}{% endblock %}


Traceback:

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\core\handlers\exception.py"
 
in inner
  41. response = get_response(request)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\core\handlers\base.py" 
in _legacy_get_response
  249. response = self._get_response(request)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\core\handlers\base.py" 
in _get_response
  217. response = self.process_exception_by_middleware(e, 
request)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\core\handlers\base.py" 
in _get_response
  215. response = response.render()

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\response.py" 
in render
  107. self.content = self.rendered_content

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\response.py" 
in rendered_content
  84. content = template.render(context, self._request)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\backends\django.py"
 
in render
  66. return self.template.render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render
  207. return self._render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in _render
  199. return self.nodelist.render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render
  990. bit = node.render_annotated(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render_annotated
  957. return self.render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\loader_tags.py"
 
in render
  177. return compiled_parent._render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in _render
  199. return self.nodelist.render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render
  990. bit = node.render_annotated(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render_annotated
  957. return self.render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\loader_tags.py"
 
in render
  177. return compiled_parent._render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in _render
  199. return self.nodelist.render(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render
  990. bit = node.render_annotated(context)

File 
"C:\Users\Alexander\Desktop\v1\lib\site-packages\django\template\base.py" 
in render_annotated
  957. return self.render(context)

File 
"C:

Re: Django Forms HorizontalRadioSelect Renderer not working.

2017-07-26 Thread Shazia Nusrat
Thank you so much for help.

Regards,

Shazia

On Tue, Jul 25, 2017 at 12:27 PM, Tim Graham  wrote:

> Replace renderer=HorizontalRadioRenderer with attrs={'class': 'inline'}
> and then style radio elements using CSS. contrib.admin uses this
> approach. Here's the CSS:
>
> https://github.com/django/django/blob/d17eaa868cd6911197dcd8b096c4f0
> 418c47007e/django/contrib/admin/static/admin/css/forms.css#L42-L66
>
> On Tuesday, July 25, 2017 at 8:10:58 AM UTC-4, Shazia Nusrat wrote:
>>
>> I am using Djnago 1.11.1. I've tried template approach but perhaps I've
>> missed out something.
>>
>> If you can provide me some workable example I will be really really
>> thankful.
>>
>> Regards,
>> Shazia
>>
>> On Tue, Jul 25, 2017 at 1:57 AM, ecas  wrote:
>>
>>> Which version of Django are you using? From 1.11 the widgets changed to
>>> a template mechanism.
>>>
>>> https://docs.djangoproject.com/en/1.11/ref/forms/widgets/#radioselect
>>>
>>> Maybe this can help:
>>> https://stackoverflow.com/questions/44187640/django-1-11-
>>> horizontal-choice-field
>>>
>>> El dimarts, 25 juliol de 2017 9:53:13 UTC+2, Shazia Nusrat va escriure:
>>>
 Hi,

 I need to select form values horizontally but couldn't get it work.

 Following is the code:

 class HorizontalRadioRenderer(forms.RadioSelect.renderer):
   def render(self):
 return mark_safe(u'\n'.join([u'%s\n' % w for w in self]))

 class ResponseForm(models.ModelForm):
 class Meta:
 model = Response
 fields = ('interviewer', 'interviewee', 'conditions',
 'comments')
 def __init__(self, *args, **kwargs):
 # expects a survey object to be passed in initially
 survey = kwargs.pop('survey')
 self.survey = survey
 super(ResponseForm, self).__init__(*args, **kwargs)
 self.uuid = random_uuid = uuid.uuid4().hex
 # add a field for each survey question, corresponding to the
 question
 # type as appropriate.
 data = kwargs.get('data')
 for q in survey.questions():
 if q.question_type == Question.TEXT:
 self.fields["question_%d" % q.pk] =
 forms.CharField(label=q.text,
 widget=forms.Textarea)
 elif q.question_type == Question.RADIO:
 question_choices = q.get_choices()
 self.fields["question_%d" % q.pk] =
 forms.ChoiceField(label=q.text,
 widget=forms.RadioSelect(rende
 rer=HorizontalRadioRenderer),
 choices = question_choices)

 Error:

 class HorizontalRadioRenderer(forms.RadioSelect.renderer):
 AttributeError: type object 'RadioSelect' has no attribute 'renderer'

 Please advise

 --
>>> 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/ms
>>> gid/django-users/d7280ade-f0c0-4c31-813f-1747f1f3cd29%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/90e4c5c4-00a0-48d8-a662-9c6fd6a4818e%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/CAD83tOz3VW3Wd2Kcg1RkaXmvDSequsuN7AxUGZdsoMZzyPVV6w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Dynamic Model ID cannot be called

2017-07-26 Thread Shazia Nusrat
Hi,

I have a simple model like below:

class Artists(models.Model):
   name = models.CharField(max_length=200)
   description = models.TextField()

   def __unicode__(self):
 return self.name

I am trying to call it in my view like below:

def artistdetail(request, id):
   artista = Artist.objects.get(id=id # this line is giving me
error.


Can someone explain me how to get the id in operational mode. I can call
IDs with filtering by name in shell. But how to set it up for the user who
uses it.


Regards,
Shazia

-- 
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/CAD83tOyL_Sdi3eeuManMXnsNBXHhvpwzGA0Tt2qXX_MgAbOUaQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


How to create reusable components in django

2017-07-26 Thread Vivek
Hello Guys
I am new to django. i am working on a web app and one of the requirements 
in the application is a dropdown list in the header that displays the 
number of users registered to a company that logins( The list is limited to 
just 10 users). so this list needs to be there for all the pages which the 
company has access to.

How do i make this list dynamic. Can i create a reusable component or 
plugin that will just display this in the layout when i call it.
Is there any other way of displaying 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/126224b3-471d-42cf-8e0d-798090a631ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


forms.Form.to_div ? and how override forms.Boundfield.label_tag?

2017-07-26 Thread threesixright
Hi All,

Just started a few weeks ago with (v1.11) *Django* (coming from Rails) and 
I *love* it! Kudos to all the dev's!

I'm fiddling with creating forms. What would be the best approach to add a 
*to_div* method to the *forms.Form* class ? many frameworks (bootstrap, 
semantic-ui, etc.)  are using:

 https://semantic-ui.com/modules/checkbox.html>">  I agree to the Terms and Conditions 


..to group fields (label + input). 

I understand I can make my own form template and just loop over the fields. 
But nicer would be (imo) if you can use a *to_div* method om the form. 

Another thing I ran into is the usage of the form label. Unlike the input 
fields that you can easily override via the widget html templates, the 
label you can not. This is implemented in the *Boundfield* *label_tag* 
method. What would be the best way to change its default behaviour?

Thanks!
36R

-- 
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/d5a2df9b-e9ea-4cd6-8fb2-355a38bacd03%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic Model ID cannot be called

2017-07-26 Thread M Hashmi
Nothing wrong with your function based view. Just try to fill data in DB
field. It will work. Because you don't have any record in DB. Try to use
'get_or_create' function.


M

On Wed, Jul 26, 2017 at 4:50 AM, Shazia Nusrat 
wrote:

> Hi,
>
> I have a simple model like below:
>
> class Artists(models.Model):
>name = models.CharField(max_length=200)
>description = models.TextField()
>
>def __unicode__(self):
>  return self.name
>
> I am trying to call it in my view like below:
>
> def artistdetail(request, id):
>artista = Artist.objects.get(id=id # this line is giving me
> error.
>
>
> Can someone explain me how to get the id in operational mode. I can call
> IDs with filtering by name in shell. But how to set it up for the user who
> uses it.
>
>
> Regards,
> Shazia
>
> --
> 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/CAD83tOyL_Sdi3eeuManMXnsNBXHhvpwzGA0Tt2q
> XX_MgAbOUaQ%40mail.gmail.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/CANoUts5nmSEeqNVa-%2B-vZ%3DPtmndnkDG%2B5gehMjA1r208u6ggxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Dynamic Model ID cannot be called

2017-07-26 Thread Shazia Nusrat
Thank you it worked.
Much appreciated.

Regards,

Shazia

On Wed, Jul 26, 2017 at 5:47 AM, M Hashmi  wrote:

> Nothing wrong with your function based view. Just try to fill data in DB
> field. It will work. Because you don't have any record in DB. Try to use
> 'get_or_create' function.
>
>
> M
>
> On Wed, Jul 26, 2017 at 4:50 AM, Shazia Nusrat 
> wrote:
>
>> Hi,
>>
>> I have a simple model like below:
>>
>> class Artists(models.Model):
>>name = models.CharField(max_length=200)
>>description = models.TextField()
>>
>>def __unicode__(self):
>>  return self.name
>>
>> I am trying to call it in my view like below:
>>
>> def artistdetail(request, id):
>>artista = Artist.objects.get(id=id # this line is giving me
>> error.
>>
>>
>> Can someone explain me how to get the id in operational mode. I can call
>> IDs with filtering by name in shell. But how to set it up for the user who
>> uses it.
>>
>>
>> Regards,
>> Shazia
>>
>> --
>> 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/ms
>> gid/django-users/CAD83tOyL_Sdi3eeuManMXnsNBXHhvpwzGA0Tt2qXX_
>> MgAbOUaQ%40mail.gmail.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/CANoUts5nmSEeqNVa-%2B-vZ%3DPtmndnkDG%
> 2B5gehMjA1r208u6ggxQ%40mail.gmail.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/CAD83tOyGW03%3DLEYF28tHD6hEL1NfH3soY01sSYSNxwCrswaJ0Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to create reusable components in django

2017-07-26 Thread Derek
You can include a template snippet into the body of the main template that 
is rendering your current view.

That snippet in turn can either be passed data (such as a user count) from 
the view that calls the main template - see  
http://code.runnable.com/UpeQSkq7JxN6AANF/dynamic-content-in-a-template-in-django-for-python
 
(but imagine the datetime.datetime.now() function being replaced by your 
own)

You can also create your own "tag" which makes the results from a function 
readily available - this example:
https://stackoverflow.com/questions/40498091/how-do-i-register-a-dynamic-inclusion-tag-within-django
looks like it might help you.

On Wednesday, 26 July 2017 13:52:54 UTC+2, Vivek wrote:
>
> Hello Guys
> I am new to django. i am working on a web app and one of the requirements 
> in the application is a dropdown list in the header that displays the 
> number of users registered to a company that logins( The list is limited to 
> just 10 users). so this list needs to be there for all the pages which the 
> company has access to.
>
> How do i make this list dynamic. Can i create a reusable component or 
> plugin that will just display this in the layout when i call it.
> Is there any other way of displaying 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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/70cb07b7-e16e-471a-8e87-7bb9f785d67b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Creating Forms from frontend like Google Survey Forms

2017-07-26 Thread Shazia Nusrat
Hi,

I need to develop a view that can help end-users create forms from the
frontend like SurveyMonkey or Google Survey Forms. Basically I need to get
admin forms at frontend and let the user's create forms on given set of
fields.

Can anyone point me to right direction please?

Thanks.
Shazia

-- 
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/CAD83tOxbP2khsHygoMC3ue7F5GCC93GQ7z%3DZWWB3kL%3Docm_Y3w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Crispy forms not showing bootstrap and save/submit button

2017-07-26 Thread Gabriel - Iulian Dumbrava
Maybe it's because you have instructed crispy to not generate the form tag and 
you have not added it yourself in the HTML code.

-- 
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/0c11d402-9e87-4532-9755-8c83d0c7860e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Group Models

2017-07-26 Thread yingi keme
What will be the best approach to designing a database schema that groups users 
in a collection of 4?

How will you create a model for lets say in an online game setting such that 
you want only 4 players in a single group based on thesame criteria amongst 
players?

Creating this model is problematic for me.

-- 
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/b0856edd-1adf-44b3-b1ac-bf20c39274ac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


ValueError: invalid literal for int() with base 10:

2017-07-26 Thread Alexander Joseph
Hello, I came across this error:

"*ValueError: invalid literal for int() with base 10:*" after I made a 
field in my models.py a ForeignKey. Below is my models.py

from django.conf import settings
from django.db import models
from django.core.urlresolvers import reverse
from django.utils import timezone
import datetime

from contacts.models import Contact
#from django.contrib.auth.models import User

# Create your models here.
class Invoice(models.Model):
created_at = models.DateTimeField(auto_now_add=True)
their_company = models.ForeignKey(Contact, 
on_delete=models.CASCADE,blank=True,
null=True,)
invoice_number = models.CharField(max_length=50, default='')
bill_to = models.CharField(max_length=255, default='')
created_by = models.ForeignKey(settings.AUTH_USER_MODEL)

def save(self, *args, **kwargs):
if not self.id:
today = datetime.date.today()
date_str = datetime.datetime.strftime(today, '%y%m%d')
doc_str = 'ACIN'
last_invoice = 
Invoice.objects.filter(invoice_number__startswith=doc_str).order_by('invoice_number').last()
if last_invoice:
last_invoice_num = last_invoice.invoice_number[-2:]
new_invoice_num = int(last_invoice_num) + 1
new_invoice_num = "%02d" % new_invoice_num
else:
new_invoice_num = '01'
self.invoice_number = doc_str + date_str + new_invoice_num
super(Invoice, self).save(*args, **kwargs)


class Meta:
ordering = ['invoice_number', ]

def __str__(self):
return self.invoice_number

def get_absolute_url(self):
return reverse("accounting:invoices:detail", kwargs={"pk": self.pk})


The 'their_company' field I think is whats giving the error. I think it is 
because it is trying to convert that field to an int but its not something 
that can be converted to an int. I'm new to django and I know I have 
something configured wrong somewhere but not sure where. 

Thanks for your 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/2fe6b89f-e93f-4035-8d8e-9d662832c063%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django Group Models

2017-07-26 Thread threesixright
Very roughly.

Something along the lines of this
I would create a Player (players) and a Match (matches) tables. 
The match table contains 4 keys (player1, player2, player3, player4) and some 
extra fields (created, status, etc.)
For each player you store some type of a skill (number) and a status 
(offline,lobby, playing, available), then alias, ping, etc.
The match-making logic could search for players within a certain skill range

> On 26 Jul 2017, at 19:07, yingi keme  wrote:
> 
> What will be the best approach to designing a database schema that groups 
> users in a collection of 4?
> 
> How will you create a model for lets say in an online game setting such that 
> you want only 4 players in a single group based on thesame criteria amongst 
> players?
> 
> Creating this model is problematic for me.
> 
> -- 
> 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/b0856edd-1adf-44b3-b1ac-bf20c39274ac%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/BED50B18-8CF7-44E7-866D-A67854921E13%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: invalid literal for int() with base 10:

2017-07-26 Thread Tim Chase
On 2017-07-26 11:52, Alexander Joseph wrote:
> "*ValueError: invalid literal for int() with base 10:*" after I
> made a field in my models.py a ForeignKey. Below is my models.py

The problem lies in this line:

> new_invoice_num = int(last_invoice_num) + 1

For some reason last_invoice_num is an invalid value to pass to
int().  You'd have to check what that actual value is that you're
passing to the function.  The error message *should* specify what
that value is:

>>> int("x")
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid literal for int() with base 10: 'x'
>>> int("")
Traceback (most recent call last):
  File "", line 1, in 
ValueError: invalid literal for int() with base 10: ''

but you seem to have truncated it so it's a little hard to tell from
the error message.  It's not None as that produces a different
message:

>>> int(None)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: int() argument must be a string, a bytes-like object or a
number, not 'NoneType'

-tkc



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+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/20170726142634.73e462ba%40bigbox.christie.dr.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: invalid literal for int() with base 10:

2017-07-26 Thread Alexander Joseph
Hi, thanks for the reply, however when I take out the 'their_company' field 
altogether everything works fine. Also in the error it references the 
their_company field. The entire error is  *"invalid literal for int() with 
base 10: 'NewCor'"* NewCor is a company in the contacts table. Thanks



On Wednesday, July 26, 2017 at 1:27:28 PM UTC-6, Tim Chase wrote:
>
> On 2017-07-26 11:52, Alexander Joseph wrote: 
> > "*ValueError: invalid literal for int() with base 10:*" after I 
> > made a field in my models.py a ForeignKey. Below is my models.py 
>
> The problem lies in this line: 
>
> > new_invoice_num = int(last_invoice_num) + 1 
>
> For some reason last_invoice_num is an invalid value to pass to 
> int().  You'd have to check what that actual value is that you're 
> passing to the function.  The error message *should* specify what 
> that value is: 
>
> >>> int("x") 
> Traceback (most recent call last): 
>   File "", line 1, in  
> ValueError: invalid literal for int() with base 10: 'x' 
> >>> int("") 
> Traceback (most recent call last): 
>   File "", line 1, in  
> ValueError: invalid literal for int() with base 10: '' 
>
> but you seem to have truncated it so it's a little hard to tell from 
> the error message.  It's not None as that produces a different 
> message: 
>
> >>> int(None) 
> Traceback (most recent call last): 
>   File "", line 1, in  
> TypeError: int() argument must be a string, a bytes-like object or a 
> number, not 'NoneType' 
>
> -tkc 
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+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/c01c643e-33a8-4514-ac52-6541982acdfc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Is there a way to use input text placeholder when using {{ form.as_p }}

2017-07-26 Thread Alexander Joseph
I'm using {{ form.as_p }} in my template and would like to be able to use 
placeholders in the individual input fields. Is there a way to do this? 
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/69313d26-f784-4cf9-82fd-72778d062dcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to use input text placeholder when using {{ form.as_p }}

2017-07-26 Thread Lee Hinde
in the init method of your form do something like this:

self.fields['verification_date'].widget.attrs["placeholder"] = 'date'

> On Jul 26, 2017, at 1:31 PM, Alexander Joseph  
> wrote:
> 
> I'm using {{ form.as_p }} in my template and would like to be able to use 
> placeholders in the individual input fields. Is there a way to do this? 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/24FEB5E0-92C9-4824-9BDD-82047D6D0AD9%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Is there a way to use input text placeholder when using {{ form.as_p }}

2017-07-26 Thread Alexander Joseph
Perfect, thanks!

On Wednesday, July 26, 2017 at 2:41:52 PM UTC-6, Lee Hinde wrote:
>
> in the init method of your form do something like this: 
>
> self.fields['verification_date'].widget.attrs["placeholder"] = 'date' 
>
> > On Jul 26, 2017, at 1:31 PM, Alexander Joseph  > wrote: 
> > 
> > I'm using {{ form.as_p }} in my template and would like to be able to 
> use placeholders in the individual input fields. Is there a way to do this? 
> 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/b6a844ba-6df3-40f7-9d87-da34cb2afefa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: ValueError: invalid literal for int() with base 10:

2017-07-26 Thread Alexander Joseph
The problem was I had records in the database from before I changed the 
'their_company' field to a ForeignKey. Before it was a CharField so some of 
the records had actual company names in them. I deleted those records since 
there wasnt any real data in there anyways, just dummy data. Everything 
works the way its supposed to now.




On Wednesday, July 26, 2017 at 1:42:26 PM UTC-6, Alexander Joseph wrote:
>
> Hi, thanks for the reply, however when I take out the 'their_company' 
> field altogether everything works fine. Also in the error it references the 
> their_company field. The entire error is  *"invalid literal for int() 
> with base 10: 'NewCor'"* NewCor is a company in the contacts table. Thanks
>
>
>
> On Wednesday, July 26, 2017 at 1:27:28 PM UTC-6, Tim Chase wrote:
>>
>> On 2017-07-26 11:52, Alexander Joseph wrote: 
>> > "*ValueError: invalid literal for int() with base 10:*" after I 
>> > made a field in my models.py a ForeignKey. Below is my models.py 
>>
>> The problem lies in this line: 
>>
>> > new_invoice_num = int(last_invoice_num) + 1 
>>
>> For some reason last_invoice_num is an invalid value to pass to 
>> int().  You'd have to check what that actual value is that you're 
>> passing to the function.  The error message *should* specify what 
>> that value is: 
>>
>> >>> int("x") 
>> Traceback (most recent call last): 
>>   File "", line 1, in  
>> ValueError: invalid literal for int() with base 10: 'x' 
>> >>> int("") 
>> Traceback (most recent call last): 
>>   File "", line 1, in  
>> ValueError: invalid literal for int() with base 10: '' 
>>
>> but you seem to have truncated it so it's a little hard to tell from 
>> the error message.  It's not None as that produces a different 
>> message: 
>>
>> >>> int(None) 
>> Traceback (most recent call last): 
>>   File "", line 1, in  
>> TypeError: int() argument must be a string, a bytes-like object or a 
>> number, not 'NoneType' 
>>
>> -tkc 
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+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/f85e13b0-06a4-42e5-a52a-c27cef9438de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I auto-fill a field in the model without showing a form field to the user?

2017-07-26 Thread Alexander Joseph
Thanks I'll pick up that book.

Would another acceptable approach be to do this in the view by overriding 
the form_valid() method? Can you tell me if there is any 
benefit/disadvantage to doing it one way or another? Thanks again





On Tuesday, July 25, 2017 at 4:48:22 PM UTC-6, Mike Dewhirst wrote:
>
> On 26/07/2017 3:15 AM, Alexander Joseph wrote: 
> > How did you learn all the methods that are available 
>
> Django is very comprehensively documented and almost any question you 
> can think up is only a google search away. Typically a search will 
> reveal a Django doc reference and StackOverflow answers. I must say 
> looking up the docs is very valuable because you learn so much else 
> besides your original quest. 
>
> Books are another good source. My preferred one is Two Scoops of Django. 
>
> Welcome. 
>
>
>

-- 
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/5c76493d-11a4-4460-9522-adc2822765e9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TypeError: __init__() takes 2 positional arguments but 3 were given (django-material)

2017-07-26 Thread Elias Coutinho
Traceback (most recent call last):
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/utils/autoreload.py",
 
line 226, in wrapper
fn(*args, **kwargs)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/core/management/commands/runserver.py",
 
line 121, in inner_run
self.check(display_num_errors=True)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/core/management/base.py",
 
line 374, in check
include_deployment_checks=include_deployment_checks,
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/core/management/base.py",
 
line 361, in _run_checks
return checks.run_checks(**kwargs)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/core/checks/registry.py",
 
line 81, in run_checks
new_errors = check(app_configs=app_configs)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/core/checks/urls.py",
 
line 14, in check_url_config
return check_resolver(resolver)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/core/checks/urls.py",
 
line 24, in check_resolver
for pattern in resolver.url_patterns:
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/utils/functional.py",
 
line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/urls/resolvers.py",
 
line 313, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", 
self.urlconf_module)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/utils/functional.py",
 
line 35, in __get__
res = instance.__dict__[self.name] = self.func(instance)
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/urls/resolvers.py",
 
line 306, in urlconf_module
return import_module(self.urlconf_name)
  File 
"/home/eliaspai/.pyenv/versions/3.5.0/lib/python3.5/importlib/__init__.py", 
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 986, in _gcd_import
  File "", line 969, in _find_and_load
  File "", line 958, in _find_and_load_unlocked
  File "", line 673, in _load_unlocked
  File "", line 662, in exec_module
  File "", line 222, in 
_call_with_frames_removed
  File "/home/eliaspai/dani/config/urls.py", line 20, in 
url(r'^cadastro/', include('danibraz.persons.urls', 
namespace='persons')),
  File 
"/home/eliaspai/danibraz/.danibraz/lib/python3.5/site-packages/django/conf/urls/__init__.py",
 
line 50, in include
urlconf_module = import_module(urlconf_module)
  File 
"/home/eliaspai/.pyenv/versions/3.5.0/lib/python3.5/importlib/__init__.py", 
line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
  File "", line 986, in _gcd_import
  File "", line 969, in _find_and_load
  File "", line 958, in _find_and_load_unlocked
  File "", line 673, in _load_unlocked
  File "", line 662, in exec_module
  File "", line 222, in 
_call_with_frames_removed
  File "/home/eliaspai/dani/danibraz/persons/urls.py", line 5, in 
from danibraz.persons.views import clients, employees
  File "/home/eliaspai/dani/danibraz/persons/views.py", line 6, in 
from danibraz.persons.forms import ClientsForm, EmployeeForm
  File "/home/eliaspai/dani/danibraz/persons/forms.py", line 31, in 
class ClientsForm(Form):
  File "/home/eliaspai/dani/danibraz/persons/forms.py", line 52, in 
ClientsForm
Stacked(1, 'addresses'),
TypeError: __init__() takes 1 positional argument but 3 were given




Em terça-feira, 25 de julho de 2017 18:16:20 UTC-3, Tim Graham escreveu:
>
> Please give the exception traceback.
>
> On Tuesday, July 25, 2017 at 3:35:41 PM UTC-4, Elias Coutinho wrote:
>>
>> Hello guys!
>>
>> I'm trying to recreate a form with Inline using django and django-stuff. 
>> I already got it once, but this is not being easy!
>>
>> I want to create a form that can register a Client and its addresses, or 
>> something similar to this link here.
>>
>> Example 1: Adding contacts.
>>
>> Example 2: Adding addresses.
>>
>> I'm trying like this:
>>
>> *Forms.py*
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> *from django import formsfrom material import Layout, Row, Fieldsetfrom 
>> .models import Clientclass Address(forms.Form):# TA FEITOpublic_place = 
>> forms.CharField(label='Logradouro')number = 
>> forms.CharField(label='Número')city = forms.CharField(label='Cidade')  
>>   state = forms.CharField(label='Estado')zipcode = 
>> forms.CharField(label='Cep')country = forms.CharField(label='País')
>> phone = forms.CharField(label='Fone')class Meta:
>> verbose_name_plural = 'endereços'verbose_name = 'endereço'def 
>> __str__(self):return self.profissaoclass 
>> ClientModelF

Re: How can I auto-fill a field in the model without showing a form field to the user?

2017-07-26 Thread Mike Dewhirst

On 27/07/2017 9:18 AM, Alexander Joseph wrote:

Thanks I'll pick up that book.

Would another acceptable approach be to do this in the view by 
overriding the form_valid() method? Can you tell me if there is any 
benefit/disadvantage to doing it one way or another? Thanks again


If you can do it in the model that is where it should be done.

I could be wrong but I believe fundamental business rules should be 
built into the model as well.


So I override the model.save() method to do the auto-fill and override 
the model.clean() method for business rules. The model clean() method 
gets called by form.is_valid() automatically on saving in the browser 
and can raise an exception if for example some perfectly valid data 
violates a business rule.


https://docs.djangoproject.com/en/1.10/ref/models/instances/#validating-objects

Consider that down the track you wish to make a phone app with access to 
your database. The only reasonable way to do that is via the model API. 
That means you have to do the work in your phone app that you did in 
your web form. It is likely easier to just call the model.full_clean() 
method before model.save() in the API.








On Tuesday, July 25, 2017 at 4:48:22 PM UTC-6, Mike Dewhirst wrote:

On 26/07/2017 3:15 AM, Alexander Joseph wrote:
> How did you learn all the methods that are available

Django is very comprehensively documented and almost any question you
can think up is only a google search away. Typically a search will
reveal a Django doc reference and StackOverflow answers. I must say
looking up the docs is very valuable because you learn so much else
besides your original quest.

Books are another good source. My preferred one is Two Scoops of
Django.

Welcome.


--
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/5c76493d-11a4-4460-9522-adc2822765e9%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/27e552a6-3a0e-3a72-d11a-958898346940%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.


Re: How can I auto-fill a field in the model without showing a form field to the user?

2017-07-26 Thread Alexander Joseph
Good to know. Thanks again!

On Monday, July 24, 2017 at 10:23:44 PM UTC-6, Alexander Joseph wrote:
>
> I'm new to django, but coming from php I think its the greatest thing ever.
>
> I have a model for Invoices ...
>
> {{{
> from django.conf import settings
> from django.db import models
> from django.core.urlresolvers import reverse
> #from django.contrib.auth.models import User
>
> # Create your models here.
> class Invoice(models.Model):
> created_at = models.DateTimeField(auto_now_add=True)
> their_company = models.CharField(max_length=255)
> invoice_number = models.CharField(max_length=50, default='')
> bill_to = models.CharField(max_length=255, default='')
> created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
> 
> class Meta:
> ordering = ['invoice_number', ]
> 
> def __str__(self):
> return self.invoice_number
> 
> def get_absolute_url(self):
> return reverse("accounting:invoices:detail", kwargs={"pk": self.pk
> })
> }}}
>
> right now the user has to put in the invoice number themselves. I want to 
> not give the user that option though - I'd like to autofill that field in 
> the database with a concatenation of the 2 digit year (17) plus 2 digit 
> month (07) plus 2 digit day (24) and then a 2 digit auto increment for 
> every invoice created on that specific date so the first invoice created 
> today would be 17072401 and the second would be 17072402, etc. I'm guessing 
> I need a field just for the date and another for the iteration of each 
> invoice.
>
> Can anyone give me some direction on this? First I'm not sure how to 
> autofill a field in the database without getting the input from the user, 
> and I'm also not sure how I would do the concatenation with the right 
> numbers. Thanks for your 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/7d5793b5-f760-4522-92eb-69f1cbb1c5d9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.