Re: Passing 3 user inputs as argument in url, for a search form

2017-10-25 Thread James Schneider
On Wed, Oct 25, 2017 at 11:29 AM, Jack  wrote:

> I am building a search form where the user inputs 3 values on a form, and
> I search the database for all records that match the 3 inputs.  Right now I
> am stuck on the user input part.
>
> If you look at my *urls.py*, you will see that I tried to put 3 keywords
> arguments in there.  Then I tried to pass the 3 keyword arguments in the
> url tag with variables from my *forms.py*.  I think this is where things
> went wrong but I'm not sure.  I don't know if the .html file can use
> variables from *forms.py*
>
> Basically what I'm trying to do is to take the 3 user inputs, and pass
> them as arguments in the URL.  Right now I'm getting:
>
> NoReverseMatch at /
>
> Reverse for 'search-results' with keyword arguments '{'pt': '', 'nb': '', 
> 'nw': ''}' not found. 1 pattern(s) tried: 
> ['search?(?P\\w+)&(?P\\w+)&(?P\\w+)']
>
>
>
> *urls.py*
> url(r'^search?(?P\w+)&(?P\w+)&(?P\w+)',
> views.IndexSearchResults.as_view(), name='search-results')
>
>
This is not the correct usage of the URL dispatcher. It should look
something like this:

url(r'^search$', views.IndexSearchResults.as_view(), name='search-results')

The URL dispatcher does not match on GET arguments within the URL, that's
left for the request object to parse.

https://docs.djangoproject.com/en/1.11/topics/http/urls/#what-the-urlconf-searches-against



*views.py*
> class IndexSearchResults(generic.ListView):
> template_name = 'search-results.html'
>
>
The view is where your GET arguments will be processed. Note that if you
are submitting the form directly to the URL above, then no validation of
the form values will be performed. If you want those values to be
validated, you should submit to a FormView to validate the results and
redirect to this search page with the GET arguments in tow. I'd imagine
that both strategies are common, since sending bad values to search against
usually just results in bad searches. The ORM takes care of most of the
security concerns in this case.

You will want to override get_queryset() to add in your GET arguments for
filtering after retrieving them from the request object. The GET arguments
are automatically captured in to a QueryDict attached to the request:

https://docs.djangoproject.com/en/1.11/ref/request-response/#querydict-objects

So, in your IndexSearchResults view:

def get_queryset(self):
queryset = super().get_queryset()

# I can do something fancy with lists of tuples to cut down on the
code, but this is more readable
pt = self.request.GET.get('pt')
nb = self.request.GET.get('nb')
nw = self.request.GET.get('nw')

if pt:
queryset = queryset.filter(property_type=pt)
if nb:
queryset = queryset.filter(number_of_bedrooms=nb)
if nw:
queryset = queryset.filter(number_of_washrooms=nw)

return queryset


This should return a queryset to the view that will filter down the list of
objects matching the GET arguments.



>
> *models.py*
> Class BuyerListing(models.Model):
>  BEDS_OPTION = (
> (BEDS_0, '0 [Studio/Bachelor]'),
> (BEDS_1, '1'),
> (BEDS_1_1, '1+1'),
> (BEDS_2, '2'),
> (BEDS_2_1, '2+1'),
> (BEDS_3, '3'),
> (BEDS_3_1, '3+1'),
> (BEDS_4, '4'),
> (BEDS_5, '5'),
> (BEDS_5_1, '5+'),
> )
>
>  WASH_OPTION = (
> (WASH_1, '1'),
> (WASH_2, '2'),
> (WASH_3, '3'),
> (WASH_4, '4'),
> (WASH_5, '5'),
> (WASH_5_1, '5+'),
> )
>
> PROPERTY_TYPE = (
> (CONDO_APARTMENT, 'Condo Apartment'),
> (DETACHED_HOUSE, 'Detached House'),
> (SEMI_DETACHED, 'Semi-detached'),
> (TOWNHOUSE, 'Townhouse'),
> )
>
> property_type = models.CharField(max_length=50)
> number_of_bedrooms = models.CharField(max_length=50, default=BEDS_0)
> number_of_washrooms = models.CharField(max_length=50, default=WASH_1)
>

This might be correct, but generally you would use an IntegerField or
FloatField here rather than CharFields for the number of beds/baths. I'm
not aware of any exceptions where a number would not be used, but you may
know of some. Searching will be slightly faster using real number fields,
and you'll be able to filter using queries for 'more than 2 bedrooms' etc.,
which you can't do with CharFields. I'd imagine that is a desired feature.

 -James

-- 
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/CA%2Be%2BciWAitr%3DkgJuAgACzC%2BFAn4wBcaDiF9qEsOC5ne0fkkHPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Package django-imagekit produces "ImportError: cannot import name conf"

2017-10-25 Thread bill.torcaso


Any help will be appreciated.


I'm having trouble using django-imagekit on AWS, under awslinux. The error 
doesn't make any sense, so I must be missing something in my AWS system 
setup.  This same code base runs fine on CentOS 6 and Ubuntu 16.x.  My 
virtualenv is activated.

This is the error, and the whole stack trace is further below.

File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/imagekit/__init__.py"
, line 2, in  

 from . import conf 

ImportError: cannot import name conf


This doesn't make any sense, because "conf.py" is right there next to 
"__init__.py":

$ ls /home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/
python2.7/dist-packages/imagekit/{__init__.py,conf.py} 

/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/
dist-packages/imagekit/conf.py 

/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/
dist-packages/imagekit/__init__.py



This is from my settings.py:

INSTALLED_APPS = ( 
 "imagekit",
 # many others ...
)



This is from pip freeze:

(www) $ pip freeze | grep image 

django-imagekit==4.0.1 # the same thing happens on 3.2.6





Traceback (most recent call last): 

 File "./manage.py", line 14, in  

 execute_from_command_line(sys.argv) 

 File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/django/core/management/__init__.py"
, line 338, in execute_from_command_line 

 utility.execute() 

 File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/django/core/management/__init__.py"
, line 312, in execute 

 django.setup() 

 File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/django/__init__.py"
, line 18, in setup 

 apps.populate(settings.INSTALLED_APPS) 

 File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/django/apps/registry.py"
, line 85, in populate 

 app_config = AppConfig.create(entry) 

 File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/django/apps/config.py"
, line 87, in create 

 module = import_module(entry) 

 File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in 
import_module 

 __import__(name) 

 File 
"/home/ec2-user/green-here/www.oxfamamerica.org/venv/www/local/lib/python2.7/dist-packages/imagekit/__init__.py"
, line 2, in  

 from . import conf 

ImportError: cannot import name conf


This is my python, in my virtualenv:
(www) $ python -V; which python 
Python 2.7.12 
~/green-here/www.oxfamamerica.org/venv/www/bin/python 


Googling produced a similar report, but that involved mixing python 2.x and 
Python 3.x; I don't have Python 3 installed on my VM instance.

What am I doing wrong?

Thanks,

  ---  Bill

-- 
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/424cbcfd-0805-4904-97b6-e6a5d0056e10%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: TypeError: unorderable types: CharField() < CharField()

2017-10-25 Thread Etienne Robillard

Hi Tim,

I need to use Django 1.4 since my application (django-livestore) is 
depending on it severely.


Anyways, I fixed the issue by adding a __lt__ method to the Field class. :)

Regards,

E

Le 2017-10-25 à 12:30, Tim Graham a écrit :
2to3 can do some simple changes for Python 3 compatibility but it 
can't do everything. I think you'll spend less time updating your 
application to a supported version of Django which supports Python 3 
than you would adding Python 3 support to Django 1.4.


On Wednesday, October 25, 2017 at 12:10:15 PM UTC-4, Etienne Robillard 
wrote:


Hi,


What could be causing this error? I'm using Python 3.5.9 and Django 1.4. I 
used the 2to3 utility to adapt Django to Python 3.

TIA,

Etienne

+ export PATH=/bin:/usr/bin:/usr/local/bin:/home/erob/bin
+ pwd
+ ROOTDIR=/home/erob/src/django-livestore
+ SATCHMO_ROOTDIR=/home/erob/src/django-livestore
+ export SATCHMO_ROOTDIR
+ CONTRIBDIR=/home/erob/src/django-livestore/contrib
+ LIBDIR=/home/erob/src/django-livestore/lib
+ DJANGO_SETTINGS_MODULE=local_settings
+ export DJANGO_SETTINGS_MODULE
+ test -z 
/home/erob/src/django-livestore/contrib/django-1.4:/home/erob/src/django-livestore:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib/site-packages
+ err=3
+ test 3 -eq 3
+ /usr/bin/python3 /usr/local/bin/httpserver.py -d -c 
/home/erob/src/django-livestore/conf/satchmo_conf.ini --disable-auth 
--settings=local_settings 
--pythonpath=/home/erob/src/django-livestore/contrib/django-1.4:/home/erob/src/django-livestore:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib/site-packages
 satchmo_store
DEBUG:django.setup() is disabled
INFO:Satchmo Logging subsystem initialized.
Sending log messages to /var/log/satchmo.log
Traceback (most recent call last):
   File "/usr/local/bin/httpserver.py", line 6, in 
 exec(compile(open(__file__).read(), __file__, 'exec'))
   File "/home/erob/src/django-hotsauce-devel/tools/httpserver.py", line 196, in 

 main(argv=sys.argv)
   File "/home/erob/src/django-hotsauce-devel/tools/httpserver.py", line 
137, in main
 WSGIHandlerClass = eval_import(app_conf['controller'])
   File 
"//home/erob/src/django-hotsauce-devel/lib/notmm/utils/pastelib//_import_string.py",
 line 28, in eval_import
 module = import_module(module_name)
   File 
"//home/erob/src/django-hotsauce-devel/lib/notmm/utils/pastelib//_import_string.py",
 line 67, in import_module
 mod = __import__(s)
   File "/home/erob/src/django-livestore/lib/satchmo_store/controller.py", line 
21, in 
 class SatchmoCookieStore(CookieStore):
   File "/home/erob/src/django-livestore/lib/satchmo_store/controller.py", 
line 22, in SatchmoCookieStore
 from django.contrib.auth.models import AnonymousUser
   File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/contrib/auth/models.py", 
line 17, in 
 from django.contrib.contenttypes.models import ContentType
   File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/contrib/contenttypes/models.py",
 line 120, in 
 class ContentType(models.Model):
   File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/base.py", 
line 99, in __new__
 new_class.add_to_class(obj_name, obj)
   File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/base.py", 
line 219, in add_to_class
 value.contribute_to_class(cls, name)
   File 
"//home/erob/src/django-livestore/contrib/django-1.4/django/db/models/fields//__init__.py",
 line 245, in contribute_to_class
 cls._meta.add_field(self)
   File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/options.py",
 line 171, in add_field
 self.local_fields.insert(bisect(self.local_fields, field), field)
TypeError: unorderable types: CharField() < CharField()

-- 
Etienne Robillard

tka...@yandex.com 
http://www.isotopesoftware.ca/

--
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/4d37fd41-c178-4fff-886a-512e41d5b42c%40googlegroups.com 
.

For more o

Passing 3 user inputs as argument in url, for a search form

2017-10-25 Thread Jack
I am building a search form where the user inputs 3 values on a form, and I 
search the database for all records that match the 3 inputs.  Right now I 
am stuck on the user input part.

If you look at my *urls.py*, you will see that I tried to put 3 keywords 
arguments in there.  Then I tried to pass the 3 keyword arguments in the 
url tag with variables from my *forms.py*.  I think this is where things 
went wrong but I'm not sure.  I don't know if the .html file can use 
variables from *forms.py*

Basically what I'm trying to do is to take the 3 user inputs, and pass them 
as arguments in the URL.  Right now I'm getting:

NoReverseMatch at /

Reverse for 'search-results' with keyword arguments '{'pt': '', 'nb': '', 'nw': 
''}' not found. 1 pattern(s) tried: 
['search?(?P\\w+)&(?P\\w+)&(?P\\w+)']



*urls.py*
url(r'^search?(?P\w+)&(?P\w+)&(?P\w+)', 
views.IndexSearchResults.as_view(), name='search-results')


*index.html *

{{ form.as_p }}



*views.py*
class IndexSearchResults(generic.ListView):
template_name = 'search-results.html'


*models.py*
Class BuyerListing(models.Model):
 BEDS_OPTION = (
(BEDS_0, '0 [Studio/Bachelor]'),
(BEDS_1, '1'),
(BEDS_1_1, '1+1'),
(BEDS_2, '2'),
(BEDS_2_1, '2+1'),
(BEDS_3, '3'),
(BEDS_3_1, '3+1'),
(BEDS_4, '4'),
(BEDS_5, '5'),
(BEDS_5_1, '5+'),
)

 WASH_OPTION = (
(WASH_1, '1'),  
(WASH_2, '2'),  
(WASH_3, '3'),  
(WASH_4, '4'),  
(WASH_5, '5'),  
(WASH_5_1, '5+'),  
)

PROPERTY_TYPE = (
(CONDO_APARTMENT, 'Condo Apartment'),
(DETACHED_HOUSE, 'Detached House'),
(SEMI_DETACHED, 'Semi-detached'),
(TOWNHOUSE, 'Townhouse'),
)

property_type = models.CharField(max_length=50)
number_of_bedrooms = models.CharField(max_length=50, default=BEDS_0)
number_of_washrooms = models.CharField(max_length=50, default=WASH_1)


*forms.py*
class MainSearch(forms.Form):

property_type = forms.ChoiceField(choices=BuyerListing.PROPERTY_TYPE)

number_of_bedrooms = forms.ChoiceField(choices=BuyerListing.BEDS_OPTION)

number_of_washrooms = 
forms.ChoiceField(choices=BuyerListing.WASH_OPTION)
  

-- 
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/deaaeafb-c8b9-45fc-9553-1c495c65dc28%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django samples

2017-10-25 Thread yingi keme
Follow this link. This is lesson 1.

https://m.youtube.com/watch?v=FNQxxpM1yOs

I think there are about 11 videos altogether. So you can search further for 
remaining video lessons.
It will give you a basic overview on how to create a simple web application 
with django.

You can later go deep if you wish. But i highly suggest u watch the videos from 
the above link.

Yingi Kem

> On 25 Oct 2017, at 4:43 PM, Ruifeng Hu  wrote:
> 
> 
> Hello everyone,
> 
>  Is there anyone who can share with me a small example, I just start learning 
>  Django.
> 
>  Than you.
> 
> Ruifeng Hu
> -- 
> 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/1d3d8a78-3c4b-4e82-a116-64ca9a870440%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/840EC294-3110-4D8D-AF71-67C3CC192D87%40gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically assign model instance to the user who created it. And only that user can edit/delete the instance.

2017-10-25 Thread mohammad k
when you submited form, form_valid will called in CreateView and give you a
instance of user form submited (form parameter in form_valid function) and
you set user to logged user (self.request.user)

On Wed, Oct 25, 2017 at 7:25 PM, Jack  wrote:

> I tried using FormView but kept running into errors.  I used your second
> response and it worked!  I don't fully understand the code, but it seems to
> work flawlessly.
>
> Thank you so much! I own you a big one.
>
> On Wednesday, October 25, 2017 at 5:57:04 AM UTC-4, k2527806 wrote:
>>
>> that your code :
>> class CreatePost(CreateView):
>> model = Post
>>
>> def form_valid(self, form):
>> form.instance.user = self.request.user
>> return super(CreatePost, self).form_valid(form)
>>
>> On Wed, Oct 25, 2017 at 1:22 PM, mohammad k  wrote:
>>
>>> use FormView
>>>
>>> https://docs.djangoproject.com/en/1.11/ref/class-based-views
>>> /generic-editing/#formview
>>>
>>> On Wed, Oct 25, 2017 at 1:21 PM, mohammad k  wrote:
>>>
 class Upload(FormView):
 http_method_names = ['get', 'post']
 template_name = 'public/upload.html'
 success_url = reverse_lazy('upload')
 form_class = UploadForms

 def get(self, request, *args, **kwargs):
 form = self.form_class(user=request.user)
 return render(request, self.template_name, {'form': form})

 def post(self, request, *args, **kwargs):
 form = self.form_class(request.POST, request.FILES,
 user=request.user)
 if form.is_valid():
 data = form.save(commit=False)
 data.user = request.user
 data.save()
 messages.add_message(request, messages.SUCCESS,
 self.success_message)
 return redirect(self.success_url)
 return render(request, self.template_name, {'form': form})

 On Wed, Oct 25, 2017 at 3:22 AM, Jack Zhang  wrote:

> Thanks for your response.  This is an off-topic question but I can't
> figure out how to get 'request' working.  I'm using the CreateView generic
> class, so there's no space to insert 'request'.  This is what my code 
> looks
> like.  When I try to run it, it tells me that request is not found.
>
> class ListingCreateView(LoginRequiredMixin, CreateView):
> model = BuyerListing
>
> form_class = PostListing(self.request.POST)
> if form.is_valid():
> form_save = form.save(commit=False)
> form_save.user = request.user # user is logged in
> form.save()
>
> def get_queryset(self):  # the user want to edit this post must be
> owner this post
> post_qs = super(PostListing, self).get_queryset()
> return post_qs.filter(user=self.request.user)
>
> On Tuesday, October 24, 2017 at 12:35:15 PM UTC-4, k2527806 wrote:
>>
>> try that in your views
>>
>> form = Dog_Form(request.POST)
>> if form.is_valid():
>> form_save = form.save(commit=False)
>> form_save.user = request.user # user is logged in
>> form.save()
>>
>>
>> On Tue, Oct 24, 2017 at 7:37 PM, Jack Zhang 
>> wrote:
>>
>>> Let's say I have a model called 'Dogs'.  Users can create instances
>>> of Dogs.  Let's say we have a user called User1.  I have 2 questions:
>>>
>>> 1. When User1 creates an instance of Dogs, how do I automatically
>>> assign that instance to User1?  I tried using a model field like this 
>>> but
>>> it doesn't pick the user automatically:
>>>
>>> user = models.ForeignKey(User, unique=False)
>>>
>>> 2. After the instance has been created, how do I make the instance
>>> only editable and removable by the user who made it?  Basically, if 
>>> User1
>>> creates an instance of Dogs, only User1 can edit and delete that 
>>> instance.
>>>
>>> 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...@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/dedbfe8b-1013
>>> -4844-b142-1e8615a1ef9a%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 emai

Re: TypeError: unorderable types: CharField() < CharField()

2017-10-25 Thread Tim Graham
2to3 can do some simple changes for Python 3 compatibility but it can't do 
everything. I think you'll spend less time updating your application to a 
supported version of Django which supports Python 3 than you would adding 
Python 3 support to Django 1.4.

On Wednesday, October 25, 2017 at 12:10:15 PM UTC-4, Etienne Robillard 
wrote:
>
> Hi,
>
>
> What could be causing this error? I'm using Python 3.5.9 and Django 1.4. I 
> used the 2to3 utility to adapt Django to Python 3.
>
> TIA,
>
> Etienne
>
> + export PATH=/bin:/usr/bin:/usr/local/bin:/home/erob/bin
> + pwd
> + ROOTDIR=/home/erob/src/django-livestore
> + SATCHMO_ROOTDIR=/home/erob/src/django-livestore
> + export SATCHMO_ROOTDIR
> + CONTRIBDIR=/home/erob/src/django-livestore/contrib
> + LIBDIR=/home/erob/src/django-livestore/lib
> + DJANGO_SETTINGS_MODULE=local_settings
> + export DJANGO_SETTINGS_MODULE
> + test -z 
> /home/erob/src/django-livestore/contrib/django-1.4:/home/erob/src/django-livestore:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib/site-packages
> + err=3
> + test 3 -eq 3
> + /usr/bin/python3 /usr/local/bin/httpserver.py -d -c 
> /home/erob/src/django-livestore/conf/satchmo_conf.ini --disable-auth 
> --settings=local_settings 
> --pythonpath=/home/erob/src/django-livestore/contrib/django-1.4:/home/erob/src/django-livestore:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib/site-packages
>  satchmo_store
> DEBUG:django.setup() is disabled
> INFO:Satchmo Logging subsystem initialized.
> Sending log messages to /var/log/satchmo.log
> Traceback (most recent call last):
>   File "/usr/local/bin/httpserver.py", line 6, in 
> exec(compile(open(__file__).read(), __file__, 'exec'))
>   File "/home/erob/src/django-hotsauce-devel/tools/httpserver.py", line 196, 
> in 
> main(argv=sys.argv)
>   File "/home/erob/src/django-hotsauce-devel/tools/httpserver.py", line 137, 
> in main
> WSGIHandlerClass = eval_import(app_conf['controller'])
>   File 
> "*/home/erob/src/django-hotsauce-devel/lib/notmm/utils/pastelib/*_import_string.py",
>  line 28, in eval_import
> module = import_module(module_name)
>   File 
> "*/home/erob/src/django-hotsauce-devel/lib/notmm/utils/pastelib/*_import_string.py",
>  line 67, in import_module
> mod = __import__(s)
>   File "/home/erob/src/django-livestore/lib/satchmo_store/controller.py", 
> line 21, in 
> class SatchmoCookieStore(CookieStore):
>   File "/home/erob/src/django-livestore/lib/satchmo_store/controller.py", 
> line 22, in SatchmoCookieStore
> from django.contrib.auth.models import AnonymousUser
>   File 
> "/home/erob/src/django-livestore/contrib/django-1.4/django/contrib/auth/models.py",
>  line 17, in 
> from django.contrib.contenttypes.models import ContentType
>   File 
> "/home/erob/src/django-livestore/contrib/django-1.4/django/contrib/contenttypes/models.py",
>  line 120, in 
> class ContentType(models.Model):
>   File 
> "/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/base.py",
>  line 99, in __new__
> new_class.add_to_class(obj_name, obj)
>   File 
> "/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/base.py",
>  line 219, in add_to_class
> value.contribute_to_class(cls, name)
>   File 
> "*/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/fields/*__init__.py",
>  line 245, in contribute_to_class
> cls._meta.add_field(self)
>   File 
> "/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/options.py",
>  line 171, in add_field
> self.local_fields.insert(bisect(self.local_fields, field), field)
> TypeError: unorderable types: CharField() < CharField()
>
> -- 
> Etienne robillardtka...@yandex.com http://www.isotopesoftware.ca/
>
>

-- 
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/4d37fd41-c178-4fff-886a-512e41d5b42c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: why donot work django

2017-10-25 Thread Vinnicyus Gracindo
see: https://docs.djangoproject.com/en/1.11/#index-first-steps

2017-10-25 12:58 GMT-03:00 Alaa Najmi :

> how to working django
>
> --
> 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/30a232e8-116d-4c3c-bcdb-4f66690dc1d4%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/CAMjWKi8vvrg9UU1B5PRiyJSqHAXTbvbmZK%2B2upBokP7RRD2%3Dgg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Django samples

2017-10-25 Thread Thiago Luiz Parolin
https://docs.djangoproject.com/en/1.11/intro/tutorial01/

This link will help you. Enjoy!

2017-10-25 13:43 GMT-02:00 Ruifeng Hu :

>
> Hello everyone,
>
>  Is there anyone who can share with me a small example, I just start
> learning  Django.
>
>  Than you.
>
> Ruifeng Hu
>
> --
> 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/1d3d8a78-3c4b-4e82-a116-64ca9a870440%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/CACTnJ02aRmvc_NN8t_fWBmdmiNVOpPRAWf4Df33e%2Banc3PHVyw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


TypeError: unorderable types: CharField() < CharField()

2017-10-25 Thread Etienne Robillard

Hi,


What could be causing this error? I'm using Python 3.5.9 and Django 1.4. I used 
the 2to3 utility to adapt Django to Python 3.

TIA,

Etienne

+ export PATH=/bin:/usr/bin:/usr/local/bin:/home/erob/bin
+ pwd
+ ROOTDIR=/home/erob/src/django-livestore
+ SATCHMO_ROOTDIR=/home/erob/src/django-livestore
+ export SATCHMO_ROOTDIR
+ CONTRIBDIR=/home/erob/src/django-livestore/contrib
+ LIBDIR=/home/erob/src/django-livestore/lib
+ DJANGO_SETTINGS_MODULE=local_settings
+ export DJANGO_SETTINGS_MODULE
+ test -z 
/home/erob/src/django-livestore/contrib/django-1.4:/home/erob/src/django-livestore:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib/site-packages
+ err=3
+ test 3 -eq 3
+ /usr/bin/python3 /usr/local/bin/httpserver.py -d -c 
/home/erob/src/django-livestore/conf/satchmo_conf.ini --disable-auth 
--settings=local_settings 
--pythonpath=/home/erob/src/django-livestore/contrib/django-1.4:/home/erob/src/django-livestore:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib:/home/erob/src/django-livestore/lib:/home/erob/src/django-livestore/contrib/site-packages
 satchmo_store
DEBUG:django.setup() is disabled
INFO:Satchmo Logging subsystem initialized.
Sending log messages to /var/log/satchmo.log
Traceback (most recent call last):
  File "/usr/local/bin/httpserver.py", line 6, in 
exec(compile(open(__file__).read(), __file__, 'exec'))
  File "/home/erob/src/django-hotsauce-devel/tools/httpserver.py", line 196, in 

main(argv=sys.argv)
  File "/home/erob/src/django-hotsauce-devel/tools/httpserver.py", line 137, in 
main
WSGIHandlerClass = eval_import(app_conf['controller'])
  File 
"/home/erob/src/django-hotsauce-devel/lib/notmm/utils/pastelib/_import_string.py",
 line 28, in eval_import
module = import_module(module_name)
  File 
"/home/erob/src/django-hotsauce-devel/lib/notmm/utils/pastelib/_import_string.py",
 line 67, in import_module
mod = __import__(s)
  File "/home/erob/src/django-livestore/lib/satchmo_store/controller.py", line 21, in 

class SatchmoCookieStore(CookieStore):
  File "/home/erob/src/django-livestore/lib/satchmo_store/controller.py", line 
22, in SatchmoCookieStore
from django.contrib.auth.models import AnonymousUser
  File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/contrib/auth/models.py", 
line 17, in 
from django.contrib.contenttypes.models import ContentType
  File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/contrib/contenttypes/models.py",
 line 120, in 
class ContentType(models.Model):
  File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/base.py", 
line 99, in __new__
new_class.add_to_class(obj_name, obj)
  File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/base.py", 
line 219, in add_to_class
value.contribute_to_class(cls, name)
  File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/fields/__init__.py",
 line 245, in contribute_to_class
cls._meta.add_field(self)
  File 
"/home/erob/src/django-livestore/contrib/django-1.4/django/db/models/options.py",
 line 171, in add_field
self.local_fields.insert(bisect(self.local_fields, field), field)
TypeError: unorderable types: CharField() < CharField()

--
Etienne Robillard
tkad...@yandex.com
http://www.isotopesoftware.ca/

--
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/26294bc0-bf6a-8d46-4aff-682386d31a0e%40yandex.com.
For more options, visit https://groups.google.com/d/optout.


why donot work django

2017-10-25 Thread Alaa Najmi
how to working django

-- 
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/30a232e8-116d-4c3c-bcdb-4f66690dc1d4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django Simple Request

2017-10-25 Thread Ruifeng Hu
Hi All,

Is there anyone who can share with me some simples of Django, I just start 
learning Django!

Thank you!

Best Regards,

Ruifeng Hu

-- 
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/7ddf0376-71a8-4597-b9e8-d6de1301a339%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Django samples

2017-10-25 Thread Ruifeng Hu

Hello everyone,

 Is there anyone who can share with me a small example, I just start 
learning  Django.

 Than you.

Ruifeng Hu

-- 
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/1d3d8a78-3c4b-4e82-a116-64ca9a870440%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically assign model instance to the user who created it. And only that user can edit/delete the instance.

2017-10-25 Thread Jack
I tried using FormView but kept running into errors.  I used your second 
response and it worked!  I don't fully understand the code, but it seems to 
work flawlessly.

Thank you so much! I own you a big one.

On Wednesday, October 25, 2017 at 5:57:04 AM UTC-4, k2527806 wrote:
>
> that your code : 
> class CreatePost(CreateView):
> model = Post
>
> def form_valid(self, form):
> form.instance.user = self.request.user
> return super(CreatePost, self).form_valid(form)
>
> On Wed, Oct 25, 2017 at 1:22 PM, mohammad k  > wrote:
>
>> use FormView
>>
>>
>> https://docs.djangoproject.com/en/1.11/ref/class-based-views/generic-editing/#formview
>>
>> On Wed, Oct 25, 2017 at 1:21 PM, mohammad k > > wrote:
>>
>>> class Upload(FormView):
>>> http_method_names = ['get', 'post']
>>> template_name = 'public/upload.html'
>>> success_url = reverse_lazy('upload')
>>> form_class = UploadForms
>>>
>>> def get(self, request, *args, **kwargs):
>>> form = self.form_class(user=request.user)
>>> return render(request, self.template_name, {'form': form})
>>>
>>> def post(self, request, *args, **kwargs):
>>> form = self.form_class(request.POST, request.FILES, 
>>> user=request.user)
>>> if form.is_valid():
>>> data = form.save(commit=False)
>>> data.user = request.user
>>> data.save()
>>> messages.add_message(request, messages.SUCCESS, 
>>> self.success_message)
>>> return redirect(self.success_url)
>>> return render(request, self.template_name, {'form': form})
>>>
>>> On Wed, Oct 25, 2017 at 3:22 AM, Jack Zhang >> > wrote:
>>>
 Thanks for your response.  This is an off-topic question but I can't 
 figure out how to get 'request' working.  I'm using the CreateView generic 
 class, so there's no space to insert 'request'.  This is what my code 
 looks 
 like.  When I try to run it, it tells me that request is not found.  

 class ListingCreateView(LoginRequiredMixin, CreateView):
 model = BuyerListing
 
 form_class = PostListing(self.request.POST)
 if form.is_valid():
 form_save = form.save(commit=False)
 form_save.user = request.user # user is logged in
 form.save()
 
 def get_queryset(self):  # the user want to edit this post must be 
 owner this post
 post_qs = super(PostListing, self).get_queryset()
 return post_qs.filter(user=self.request.user)

 On Tuesday, October 24, 2017 at 12:35:15 PM UTC-4, k2527806 wrote:
>
> try that in your views
>
> form = Dog_Form(request.POST)
> if form.is_valid():
> form_save = form.save(commit=False)
> form_save.user = request.user # user is logged in
> form.save()
>
>
> On Tue, Oct 24, 2017 at 7:37 PM, Jack Zhang  
> wrote:
>
>> Let's say I have a model called 'Dogs'.  Users can create instances 
>> of Dogs.  Let's say we have a user called User1.  I have 2 questions:
>>
>> 1. When User1 creates an instance of Dogs, how do I automatically 
>> assign that instance to User1?  I tried using a model field like this 
>> but 
>> it doesn't pick the user automatically:
>>
>> user = models.ForeignKey(User, unique=False)
>>
>> 2. After the instance has been created, how do I make the instance 
>> only editable and removable by the user who made it?  Basically, if 
>> User1 
>> creates an instance of Dogs, only User1 can edit and delete that 
>> instance. 
>>
>> 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...@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/dedbfe8b-1013-4844-b142-1e8615a1ef9a%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...@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/950d853a-ade3-4d27-8e23-a47c6b70c80e%4

Re: Simple file uploading app

2017-10-25 Thread Jani Tiainen
Hi.

I did simple pic uploader while ago.

Source code is available at https://github.com/jtiai/picpaster

25.10.2017 5.58 ip. "guettli"  kirjoitti:

> I need a simple file uploading app.
>
> Every user should be able to upload files to his own area.
>
> This is the basic feature. You could think of additional goodies, but the
> first step is
> above feature.
>
> I tried to find an application which implements this, but failed.
>
> I tried this and other searches:
>
> https://djangopackages.org/search/?q=upload
>
>
> Before I start coding, I wanted to ask here, because I prefer re-using to
> re-inventing :-)
>
> Do you know an app which gives me this feature?
>
> Regards,
>   Thomas Güttler
>
>
> --
> 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/f97451b7-97f3-47e6-bf99-bef13c7b0d9b%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/CAHn91oey4e3XJEdHFqjoAx%2BCh73b%2B8DYFjfbAev%2B0kJCnU7Pbg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Simple file uploading app

2017-10-25 Thread guettli
I need a simple file uploading app.

Every user should be able to upload files to his own area.

This is the basic feature. You could think of additional goodies, but the 
first step is
above feature.

I tried to find an application which implements this, but failed.

I tried this and other searches:

https://djangopackages.org/search/?q=upload


Before I start coding, I wanted to ask here, because I prefer re-using to 
re-inventing :-)

Do you know an app which gives me this feature?

Regards,
  Thomas Güttler


-- 
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/f97451b7-97f3-47e6-bf99-bef13c7b0d9b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding several user models

2017-10-25 Thread James Schneider
> When you say 'share the database', are you referring to the same database
> server but separate database instances? Or are you expecting both projects
> to access the same tables in the same database instance?
>

It will be the same tables in the same database instance.


You like to live dangerously don't you? ;-)

That fact actually changes my perspective quite a bit. Typically with
separate but integrated projects, one project holds the actual user data,
and the other keeps a copy of a minimal subset of meta data, enough to
identify the user in the other application when necessary. That was my
assumption for my original response.

If they share the same underlying table, then they'll definitely need to be
in sync, and I would definitely recommend having a common model definition
between the two projects. You should probably pick one of the projects as
the 'master' where the migrations for that project will handle the
Participants table, and the other project model will be marked as unmanaged
to avoid migrations being needed. The likely candidate is the Participants
project since it has the more complicated functionality associated with its
user model.



>
>
> All of those issues aside, I wouldn't start with an abstract model
> inheriting from AbstractUser. I would create a clean abstract model
> inheriting from models.Model, and copy everything from AbstractUser over to
> your new abstract user model. Your Admin project would then define a
> concrete user model that inherits directly from your new abstract user
> model. Over in the Participant project, your concrete model would inherit
> from the abstract model created in the Admin project, and also
> from AbstractBaseUser and the PermissionsMixin, just like AbstractUser
> does. This way, you have a single model controlling what fields are made
> available in both applications, but only the Participant project model
> contains the extra machinery to use that model to authenticate/authorize
> users. The copy/paste operation probably violates DRY for some purists, but
> you'll likely be modifying those fields at some point anyway, so I consider
> it a necessary evil.
>

I agree with this setup - however I would like more fine grained
permissions in the admin project.


Sure, but having the models set up in such a way shouldn't prevent that.
The Participant objects are not real end users in that context (or at
least, I'm assuming they can't log in), just regular models, so they won't
need permissions assigned to them. It would be a combination of assigning
correct permissions to your Admin users and filtering the views and
serializers appropriately.

-James

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


Re: Automatically assign model instance to the user who created it. And only that user can edit/delete the instance.

2017-10-25 Thread mohammad k
that your code :
class CreatePost(CreateView):
model = Post

def form_valid(self, form):
form.instance.user = self.request.user
return super(CreatePost, self).form_valid(form)

On Wed, Oct 25, 2017 at 1:22 PM, mohammad k  wrote:

> use FormView
>
> https://docs.djangoproject.com/en/1.11/ref/class-based-
> views/generic-editing/#formview
>
> On Wed, Oct 25, 2017 at 1:21 PM, mohammad k  wrote:
>
>> class Upload(FormView):
>> http_method_names = ['get', 'post']
>> template_name = 'public/upload.html'
>> success_url = reverse_lazy('upload')
>> form_class = UploadForms
>>
>> def get(self, request, *args, **kwargs):
>> form = self.form_class(user=request.user)
>> return render(request, self.template_name, {'form': form})
>>
>> def post(self, request, *args, **kwargs):
>> form = self.form_class(request.POST, request.FILES,
>> user=request.user)
>> if form.is_valid():
>> data = form.save(commit=False)
>> data.user = request.user
>> data.save()
>> messages.add_message(request, messages.SUCCESS,
>> self.success_message)
>> return redirect(self.success_url)
>> return render(request, self.template_name, {'form': form})
>>
>> On Wed, Oct 25, 2017 at 3:22 AM, Jack Zhang 
>> wrote:
>>
>>> Thanks for your response.  This is an off-topic question but I can't
>>> figure out how to get 'request' working.  I'm using the CreateView generic
>>> class, so there's no space to insert 'request'.  This is what my code looks
>>> like.  When I try to run it, it tells me that request is not found.
>>>
>>> class ListingCreateView(LoginRequiredMixin, CreateView):
>>> model = BuyerListing
>>>
>>> form_class = PostListing(self.request.POST)
>>> if form.is_valid():
>>> form_save = form.save(commit=False)
>>> form_save.user = request.user # user is logged in
>>> form.save()
>>>
>>> def get_queryset(self):  # the user want to edit this post must be
>>> owner this post
>>> post_qs = super(PostListing, self).get_queryset()
>>> return post_qs.filter(user=self.request.user)
>>>
>>> On Tuesday, October 24, 2017 at 12:35:15 PM UTC-4, k2527806 wrote:

 try that in your views

 form = Dog_Form(request.POST)
 if form.is_valid():
 form_save = form.save(commit=False)
 form_save.user = request.user # user is logged in
 form.save()


 On Tue, Oct 24, 2017 at 7:37 PM, Jack Zhang  wrote:

> Let's say I have a model called 'Dogs'.  Users can create instances of
> Dogs.  Let's say we have a user called User1.  I have 2 questions:
>
> 1. When User1 creates an instance of Dogs, how do I automatically
> assign that instance to User1?  I tried using a model field like this but
> it doesn't pick the user automatically:
>
> user = models.ForeignKey(User, unique=False)
>
> 2. After the instance has been created, how do I make the instance
> only editable and removable by the user who made it?  Basically, if User1
> creates an instance of Dogs, only User1 can edit and delete that instance.
>
> 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...@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/dedbfe8b-1013
> -4844-b142-1e8615a1ef9a%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/ms
>>> gid/django-users/950d853a-ade3-4d27-8e23-a47c6b70c80e%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.co

Re: Automatically assign model instance to the user who created it. And only that user can edit/delete the instance.

2017-10-25 Thread mohammad k
use FormView

https://docs.djangoproject.com/en/1.11/ref/class-based-views/generic-editing/#formview

On Wed, Oct 25, 2017 at 1:21 PM, mohammad k  wrote:

> class Upload(FormView):
> http_method_names = ['get', 'post']
> template_name = 'public/upload.html'
> success_url = reverse_lazy('upload')
> form_class = UploadForms
>
> def get(self, request, *args, **kwargs):
> form = self.form_class(user=request.user)
> return render(request, self.template_name, {'form': form})
>
> def post(self, request, *args, **kwargs):
> form = self.form_class(request.POST, request.FILES,
> user=request.user)
> if form.is_valid():
> data = form.save(commit=False)
> data.user = request.user
> data.save()
> messages.add_message(request, messages.SUCCESS,
> self.success_message)
> return redirect(self.success_url)
> return render(request, self.template_name, {'form': form})
>
> On Wed, Oct 25, 2017 at 3:22 AM, Jack Zhang  wrote:
>
>> Thanks for your response.  This is an off-topic question but I can't
>> figure out how to get 'request' working.  I'm using the CreateView generic
>> class, so there's no space to insert 'request'.  This is what my code looks
>> like.  When I try to run it, it tells me that request is not found.
>>
>> class ListingCreateView(LoginRequiredMixin, CreateView):
>> model = BuyerListing
>>
>> form_class = PostListing(self.request.POST)
>> if form.is_valid():
>> form_save = form.save(commit=False)
>> form_save.user = request.user # user is logged in
>> form.save()
>>
>> def get_queryset(self):  # the user want to edit this post must be
>> owner this post
>> post_qs = super(PostListing, self).get_queryset()
>> return post_qs.filter(user=self.request.user)
>>
>> On Tuesday, October 24, 2017 at 12:35:15 PM UTC-4, k2527806 wrote:
>>>
>>> try that in your views
>>>
>>> form = Dog_Form(request.POST)
>>> if form.is_valid():
>>> form_save = form.save(commit=False)
>>> form_save.user = request.user # user is logged in
>>> form.save()
>>>
>>>
>>> On Tue, Oct 24, 2017 at 7:37 PM, Jack Zhang  wrote:
>>>
 Let's say I have a model called 'Dogs'.  Users can create instances of
 Dogs.  Let's say we have a user called User1.  I have 2 questions:

 1. When User1 creates an instance of Dogs, how do I automatically
 assign that instance to User1?  I tried using a model field like this but
 it doesn't pick the user automatically:

 user = models.ForeignKey(User, unique=False)

 2. After the instance has been created, how do I make the instance only
 editable and removable by the user who made it?  Basically, if User1
 creates an instance of Dogs, only User1 can edit and delete that instance.

 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...@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/dedbfe8b-1013-4844-b142-1e8615a1ef9a%40goog
 legroups.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/ms
>> gid/django-users/950d853a-ade3-4d27-8e23-a47c6b70c80e%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/CACOk0TzRtASzQuPsHFWSmef%3D_P8bdb-H-Y_YEaG6vJfg0sBiKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Automatically assign model instance to the user who created it. And only that user can edit/delete the instance.

2017-10-25 Thread mohammad k
class Upload(FormView):
http_method_names = ['get', 'post']
template_name = 'public/upload.html'
success_url = reverse_lazy('upload')
form_class = UploadForms

def get(self, request, *args, **kwargs):
form = self.form_class(user=request.user)
return render(request, self.template_name, {'form': form})

def post(self, request, *args, **kwargs):
form = self.form_class(request.POST, request.FILES,
user=request.user)
if form.is_valid():
data = form.save(commit=False)
data.user = request.user
data.save()
messages.add_message(request, messages.SUCCESS,
self.success_message)
return redirect(self.success_url)
return render(request, self.template_name, {'form': form})

On Wed, Oct 25, 2017 at 3:22 AM, Jack Zhang  wrote:

> Thanks for your response.  This is an off-topic question but I can't
> figure out how to get 'request' working.  I'm using the CreateView generic
> class, so there's no space to insert 'request'.  This is what my code looks
> like.  When I try to run it, it tells me that request is not found.
>
> class ListingCreateView(LoginRequiredMixin, CreateView):
> model = BuyerListing
>
> form_class = PostListing(self.request.POST)
> if form.is_valid():
> form_save = form.save(commit=False)
> form_save.user = request.user # user is logged in
> form.save()
>
> def get_queryset(self):  # the user want to edit this post must be
> owner this post
> post_qs = super(PostListing, self).get_queryset()
> return post_qs.filter(user=self.request.user)
>
> On Tuesday, October 24, 2017 at 12:35:15 PM UTC-4, k2527806 wrote:
>>
>> try that in your views
>>
>> form = Dog_Form(request.POST)
>> if form.is_valid():
>> form_save = form.save(commit=False)
>> form_save.user = request.user # user is logged in
>> form.save()
>>
>>
>> On Tue, Oct 24, 2017 at 7:37 PM, Jack Zhang  wrote:
>>
>>> Let's say I have a model called 'Dogs'.  Users can create instances of
>>> Dogs.  Let's say we have a user called User1.  I have 2 questions:
>>>
>>> 1. When User1 creates an instance of Dogs, how do I automatically assign
>>> that instance to User1?  I tried using a model field like this but it
>>> doesn't pick the user automatically:
>>>
>>> user = models.ForeignKey(User, unique=False)
>>>
>>> 2. After the instance has been created, how do I make the instance only
>>> editable and removable by the user who made it?  Basically, if User1
>>> creates an instance of Dogs, only User1 can edit and delete that instance.
>>>
>>> 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...@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/dedbfe8b-1013-4844-b142-1e8615a1ef9a%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/950d853a-ade3-4d27-8e23-a47c6b70c80e%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/CACOk0TxLHOc_r_c_53650JR57NmKm%3DDDtAOt%2BayWr0k8V5rwKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Adding several user models

2017-10-25 Thread Andréas Kühne
James,

Thank you for your long and detailed answer. I agree with you in all of
your points and I think that your solution is correct.

2017-10-25 2:52 GMT+02:00 James Schneider :

>
>
> On Oct 24, 2017 3:46 AM, "Andréas Kühne" 
> wrote:
>
> Hi all,
>
> I would love to pick your collective brains for a second. I am working on
> an application that will be first and foremost an administration system. As
> such there will be very few users in the system. It will have a front end
> developed in angular 5 and a Django rest framework backend.
>
> I have got the solution up and running currently and it works as I think
> it should. However - now I have another idea that I would like to hear your
> opinions on.
>
> Connected to this system we will also have other portals where a user will
> be able to login - NOT the same user as the user that logs onto the
> administration system - but an entirely different concept (a participant).
> These portals will probably be running on another machine (but not
> necessarily) and can have their own user concept. This application will
> also be more of a traditional Django project with a standard view and
> template driven design.
>
> I am thinking about creating the Participant model separate from the User
> (they are different concepts) and therefore was wondering if it would be
> possible to create the Participant model based on an AbstractUser from
> django contrib auth and then in the portal project use that as the user
> model?
>
>
> Short answer is yes, with caveats, but it may not be recommended.
>
> The long answer: There's no technical reason that a model defined in one
> project cannot serve as a reference for another project. The common code
> just needs to be accessible from both projects. This works the same way as
> any other Python library, because after all, Django models are just Python
> code.
>
> There are logical and design issues with doing it, though. A change in the
> Admin project for the abstract user model will now propagate to the
> Participant project, possibly in a negative way. You'll need to execute
> tests for both your Admin and Participant projects whenever changes are
> made to that model. Adding new features is usually easy, but deprecating
> code can be a nightmare, as you now have two code bases that need to be
> analyzed rather than one. You've also directly coupled the two projects
> together from a semantic versioning standpoint. Even with no changes to the
> Participant project, a change to the abstract model in the Admin project
> now forces a migration for the Participant project (if a field is
> modified), and likely a version bump for the Participant project so that
> those running your software pick up the changes, even though there were no
> modifications made to the Participant project itself.
>
> I'd ask how important it is that these two models be coupled in such a
> way? Granted, adding common fields between the two is handy, but for the
> reasons above, it can be dangerous. It's likely that the Admin project only
> needs a very small subset of the fields that the Participant project needs,
> and the Admin app has no use for any of the authentication/authorization
> backend functionality that gets dragged along with AbstractUser.
>

I think that your solution here would be perfect for my use. Decoupling the
users in such a way would not be a problem.


>
> Has anyone every done anything similar? Is this idea completely wrong? Any
> other things that I should think about?
>
>
> Yes, in the sense that developing a 3rd party app for both projects is
> effectively what you are doing. These are the same issues faced by 3rd
> party app developers for Django, where a 1-line change in a 3rd party
> module requires a migration for anyone that is using the app.
>
> It's not necessarily wrong, there are just a number of issues to consider
> with the coupling between the projects that you'll be creating.
>
>
> My main reason behind this idea is that the applications will share the
> database, but be completely different projects and shouldn’t necessarily
> share a web app? Is this also a wrong idea or does this sound sane?
>
>
> When you say 'share the database', are you referring to the same database
> server but separate database instances? Or are you expecting both projects
> to access the same tables in the same database instance?
>

It will be the same tables in the same database instance.


>
>
> All of those issues aside, I wouldn't start with an abstract model
> inheriting from AbstractUser. I would create a clean abstract model
> inheriting from models.Model, and copy everything from AbstractUser over to
> your new abstract user model. Your Admin project would then define a
> concrete user model that inherits directly from your new abstract user
> model. Over in the Participant project, your concrete model would inherit
> from the abstract model created in the Admin project, and also
> from AbstractBaseUser and the Permission