Re: ValueError source code string cannot contain null bytes

2018-05-12 Thread Arif Arman
Hi I am having the same error. Did you manage to solve it?

On Thursday, December 7, 2017 at 10:30:16 AM UTC+6, Rajeshwaran wrote:
>
> Hi All,
>
> I am facing this "ValueError: source code string cannot contain null 
> bytes" error when i create a sqlite3 database and run the application.
>
> Steps that i do :
>
>
>1. Create database using db browser for SQLITE3
>2. Create model by running "python manage.py inspectdb > models.py"
>3. Run the application by "python manage.py runserver"
>
> Could someone please help me with this issue.
>
> Thanks,
> Rajeshwaran
>

-- 
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/d8d4634c-a1f2-45a2-b1a3-6fb58cf8ce5b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploy on windows IIS

2018-05-12 Thread Majid Hojati
Hi,
I faced a question, Do you unistalled iis and installed Apache?Also If I 
want to use Geoserver which runs on TomCat How can I use it beside django?

On Friday, May 11, 2018 at 11:07:19 PM UTC+4:30, Matthew Pava wrote:
>
> I just go straight to the source or Google around.
>
> https://httpd.apache.org/docs/2.4/platform/windows.html
>
> Apache has different flavors for Windows.  We’re either using ApacheHaus 
> or Apache Lounge.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Majid Hojati
> *Sent:* Friday, May 11, 2018 1:33 PM
> *To:* Django users
> *Subject:* Re: Deploy on windows IIS
>
>  
>
> Is there any good tuturial which I can use Apache? I am also using 
> Geoserver which runs on tomcat port 8080 I hope it does not make any 
> problems
>
> On Friday, May 11, 2018 at 10:55:45 PM UTC+4:30, Matthew Pava wrote:
>
> I know it doesn’t directly answer your question, but I have Django running 
> on Windows Server 2012.  After wrestling with IIS for just a bit, I decided 
> to just use Apache instead.
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Majid Hojati
> *Sent:* Friday, May 11, 2018 12:52 PM
> *To:* Django users
> *Subject:* Deploy on windows IIS
>
>  
>
> Hi,
>
> I have faced a problem while deploying django on windows server 2008 with 
> IIS
>
> I followed this 
>
>
> http://blog.mattwoodward.com/2016/07/running-django-application-on-windows.html
>
>  
>
> and it returns unexpectedly exited error. I am using python 3.6 and the 
> development pythons server runs with no problem but I can not configure 
> factcgi,
>
> What options do I have? I can not even find the problem with this error. 
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com.
> To post to this group, send email to djang...@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/81d75081-c368-498d-9980-3b0e0d0feefe%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 djang...@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/52e5c404-69ff-45a1-910d-aeda09ad58f0%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/afc948bd-7b65-4bd7-9ed2-942fa7be0493%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Deploy on windows IIS

2018-05-12 Thread Majid Hojati
Which Mode_wsgi you used for python 3.6 x86 and apache2.4 Haus x64 for 
windows ?

On Friday, May 11, 2018 at 11:07:19 PM UTC+4:30, Matthew Pava wrote:
>
> I just go straight to the source or Google around.
>
> https://httpd.apache.org/docs/2.4/platform/windows.html
>
> Apache has different flavors for Windows.  We’re either using ApacheHaus 
> or Apache Lounge.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Majid Hojati
> *Sent:* Friday, May 11, 2018 1:33 PM
> *To:* Django users
> *Subject:* Re: Deploy on windows IIS
>
>  
>
> Is there any good tuturial which I can use Apache? I am also using 
> Geoserver which runs on tomcat port 8080 I hope it does not make any 
> problems
>
> On Friday, May 11, 2018 at 10:55:45 PM UTC+4:30, Matthew Pava wrote:
>
> I know it doesn’t directly answer your question, but I have Django running 
> on Windows Server 2012.  After wrestling with IIS for just a bit, I decided 
> to just use Apache instead.
>
>  
>
> *From:* django...@googlegroups.com [mailto:django...@googlegroups.com] *On 
> Behalf Of *Majid Hojati
> *Sent:* Friday, May 11, 2018 12:52 PM
> *To:* Django users
> *Subject:* Deploy on windows IIS
>
>  
>
> Hi,
>
> I have faced a problem while deploying django on windows server 2008 with 
> IIS
>
> I followed this 
>
>
> http://blog.mattwoodward.com/2016/07/running-django-application-on-windows.html
>
>  
>
> and it returns unexpectedly exited error. I am using python 3.6 and the 
> development pythons server runs with no problem but I can not configure 
> factcgi,
>
> What options do I have? I can not even find the problem with this error. 
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com.
> To post to this group, send email to djang...@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/81d75081-c368-498d-9980-3b0e0d0feefe%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 djang...@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/52e5c404-69ff-45a1-910d-aeda09ad58f0%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/da02dd76-72a7-4c41-9c9e-c9cf9a743345%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating models from json url feed

2018-05-12 Thread Ryan Nowakowski


On May 10, 2018 7:40:47 AM CDT, Matt Snelgar  wrote:
>
>
>I am making a django app to browse available products at different
>markets. 
>I am getting data for my models from a JSON url feed, 
>
>I am not sure on the best approach to turn this data into models as the
>
>feed for a single market can contain upwards of 50k items.
>
>
>Models - feel free to suggest any improvements on these
>
># Details of a sellable products
>class Product(models.Model):
>   item = models.IntegerField(primary_key=True, auto_created=False)
>name = models.CharField(max_length=40)
>
># Market where products can be bought, some markets will cater to
>multiple suburbs.
>class Market(models.Model):
>id = models.IntegerField(primary_key=True, auto_created=True)
>name = models.CharField(max_length=40)
>
># Nearby suburbs can share the one market
>class Suburb(models.Model):
>name = models.CharField(max_length=30)
>market = models.ForeignKey(Market, on_delete=models.SET_NULL,
>null=True)
>
># Actual product for sale
>class ProductForSale(models.Model):
>sale = models.IntegerField(primary_key=True)
>product = models.ForeignKey(Product, on_delete=models.SET_NULL,
>null=True)
>cost = models.IntegerField(default=1)
>owner = models.CharField(max_length=30)
>quantity = models.IntegerField(default=1)
>market = models.ForeignKey(Market,on_delete=models.SET_NULL, null=True
>)
>Feed of markets products example
>
>"market_products": [
>{
>"id":11654,
>"item":123,
>"owner":"Bob",
>"suburb":"Springvale",
>"cost":3,
>"quantity":1,
>
>},
>{
>"id":11655,
>"item":123,
>"owner":"Sarah",
>"suburb":"Sunnyville",
>"cost":5,
>"quantity":2,
>
>},
>
>This is how I am trying to populate my ProductForSale models - I don't
>know 
>if this is the correct approach for the Product FK, or how to link the 
>suburb to its Market FK
>
>markets = Market.objects.all()
>for market in markets:
>url = "jsonurl"
>response = urllib.request.urlopen(url)
>data = json.loads(response.read())
>for entry in data['market_products']:
>new_product_sale = ProductForSale.objects.create(
>product = Product.objects.get(item=entry['item']),
>cost = entry['cost'],
>owner = entry['owner'],
>quantity = entry['quantity']
>)
>new_product_sale.save()
>
>Is there a point where I should create a separate model for each
>markets 
>products, or is it fine to house them all in the one model?

Do products from different markets have many different fields?  Or are most of 
the fields common?

Do you need to be able to filter on products across markets? Or are most of 
your product queries specific to a particular market?

-- 
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/5D327C5E-124E-423D-A3D6-9BEBD266565C%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.


Re: @mark_safe decorator and filters & tags

2018-05-12 Thread Tim Graham
Seems to be a regression: https://code.djangoproject.com/ticket/29400

On Tuesday, May 8, 2018 at 4:45:14 PM UTC-4, Torsten Bronger wrote:
>
> Hallöchen! 
>
> Up to Django 1.11, I had the following pattern frequently in my 
> code: 
>
> @register.filter 
> @mark_safe 
> def myfilter(value): 
> ... 
>
> Smilarly for tags.  This has worked for years, however, with Django 
> 2.0, this leads to the TemplateError saying that "myfilter requires 
> 0 arguments, 1 provided".  For tags, it results in an IndexError 
> because the "params" list when processing the tag is empty. 
>
> If I make @mark_safe the outmost (i.e. first) decorator, no 
> exception occurs – but the output is escaped HTML instead of 
> passed-through HTML. 
>
> The safe and obvious workaround is to use mark_safe() as a function 
> instead of @mark_safe.  Would be a pity, though. 
>
> Is this a bug or am I doing something wrong? 
>
> Tschö, 
> Torsten. 
>
> -- 
> Torsten Bronger 
>
>

-- 
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/30a1f57b-892a-4a13-803a-5770b7591964%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How Can I Select Date Based on Monday Date?

2018-05-12 Thread Alexander Joseph
I'm building a timesheet app for employees and would like the employees to 
be able to select a day of the week date based on what the date was on 
Monday.

ie. the user inputs the Monday date of the timesheet, then for each row 
they need to fill out they can select the Day/Date for each day that week 
so that those hours they input get assigned to that specific day/date. The 
easiest way I can think of would be to make a list of choices in the Model 
such as ...

MONDAY = 'MO'
TUESDAY = 'TU'
WEDNESDAY = 'WE'
THURSDAY = 'TH'
FRIDAY = 'FR'
SATURDAY = 'SA'
SUNDAY = 'SU'

DAY_CHOICES = (
(MONDAY, 'Monday'),
(TUESDAY, 'Tuesday'),
(WEDNESDAY, 'Wednesday'),
(THURSDAY, 'Thursday'),
(FRIDAY, 'Friday'),
(SATURDAY, 'Saturday'),
(SUNDAY, 'Sunday'),
)
day = models.CharField(
max_length=2,
choices=DAY_CHOICES,
default=MONDAY,
)

This would work except I also want to include the actual date of the day 
they select, based on the Monday date that they put in in another Model

Is there a library or package I can use 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/6089eafa-7495-4ec4-a539-624cf95014b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


The path to my login template after registration is incorrect, but the path to the registration template in the same directory is correct, I don't understand why.

2018-05-12 Thread Anthony Orona

I set up user registration by subclassing generic.CreateView in an app 
called Accounts. and I then set up my urls using django.contrib.auth.urls. 
I can register a user but when I try to redirect to the login page, I get 
this error: 


~//workspace/web/goldrush/gr_backend/templates/registration/login.html 
(Source does not exist)

I don't understand why and I have been fiddling with this for an hour to no 
avail. 

The Accounts App, my settings, and project-level urls are available at: 
[this link](https://github.com/Ajorona/ecommercedjango) to my github. I am 
not going to put this project into production so I left my project secret 
key visible ¯\_(ツ)_/¯. Can someone help me understand how to correctly 
configure my templates for the Accounts App? I am using a project-level 
templates directory.

-- 
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/7338bc1f-cd49-44e3-88a8-4af1606e331b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: The path to my login template after registration is incorrect, but the path to the registration template in the same directory is correct, I don't understand why.

2018-05-12 Thread Jason
here is no templates folder in the gr_backend package.  nor are there any 
template directories or files in that repository

On Saturday, May 12, 2018 at 4:59:28 PM UTC-4, Anthony Orona wrote:
>
>
> I set up user registration by subclassing generic.CreateView in an app 
> called Accounts. and I then set up my urls using django.contrib.auth.urls. 
> I can register a user but when I try to redirect to the login page, I get 
> this error: 
>
> 
> ~//workspace/web/goldrush/gr_backend/templates/registration/login.html 
> (Source does not exist)
>
> I don't understand why and I have been fiddling with this for an hour to 
> no avail. 
>
> The Accounts App, my settings, and project-level urls are available at: 
> [this link](https://github.com/Ajorona/ecommercedjango) to my github. I 
> am not going to put this project into production so I left my project 
> secret key visible ¯\_(ツ)_/¯. Can someone help me understand how to 
> correctly configure my templates for the Accounts App? I am using a 
> project-level templates directory.
>

-- 
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/2229af54-f346-43ce-8c6c-1275cbf9b848%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to make queries using Mysql JSON field and django 2

2018-05-12 Thread Jason
the default jsonfield field type for django is postgres only, but there's 
support for mysql 5.7 via a third party package 
https://github.com/adamchainz/django-mysql.  specifically 
https://django-mysql.readthedocs.io/en/latest/model_fields/json_field.html

On Friday, May 11, 2018 at 3:30:42 PM UTC-4, mark wrote:
>
> I have a model Document that has a json field "metadata" containing a 
> dictionary of different values. One example:
>
> {"Orientation": "Landscape", 
> "Address": "Bethany Home Road", 
> "Photo Type": "Many People", 
> "a boolean": false, 
> "Person": ["Sam Smith", "Hank Jones"], 
> "Date": "05/13/2018", 
> "Location": "Washington DC", 
> "Decade": "2020"}
>
> I can write a query to find all the record(s) in the Document table that 
> the "Person" field contains "Sam Smith" like this
>
> Document.objects.filter(metadata__Person__contains='Sam Smith')
>
> Is there a way to write a query to find all the Documents that have "Sam*" 
> in the metadata field? 
>
> For example, if there were another document that had "Sammy Jacobs" in the 
> "Person" field, the query would return both that record and the record with 
> the "Sam Smith" in the Person field. 
>
> Either some sort of "or" condition within the query that would allow me to 
> search for "Sam Smith" or "Sammy Jacobs". Or, some sort of regex that I can 
> put in for the search criteria that says search for all the "Sam*" 
> occurrences in the "Person" list.
>
> I have been googling for a solution, but have not found one yet.
>
> Thanks!
>
> Mark
>
>  
>
>

-- 
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/cf094ca1-2d79-4f00-a264-81102fc32f01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


SQL select statements to Django ORM

2018-05-12 Thread Gerald Brown
As I have said previously, I am new to Django ORM so I would like to know 
howto/find reference to Django ORM Query to the following SQL Select 
statements:

1. From Mariadb. 

SELECT name, date_of_birth, *TIMESTAMPDIFF(YEAR,date_of_birth,'2014-08-02'/or 
curdate())* AS age FROM some table.

2. General SQL statement
SELECT field1, field2, field10 from some table

3. How to see all of the data from those statements which SQL shows me. 

I have read (several times) the documentation @ 
https://docs.djangoproject.com/en/2.0/topics/db/queries/. They show numerous 
examples of Queries but none of them show the results from those queries.

When I do get results to show ONLY the fields that are in my __str__ statement 
show up. If I add additional fields they also
show up in my FK list, which I don't want.

Thanks for all previous help from this group.

-- 
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/a3522074-a3d5-4d8a-b905-df06b14be753%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating models from json url feed

2018-05-12 Thread Matt Snelgar
All of the products will share the same fields.

I would filter on products, but my searches would only be restricted to one
market at a time.

On Sun, May 13, 2018 at 1:51 AM, Ryan Nowakowski 
wrote:

>
>
> On May 10, 2018 7:40:47 AM CDT, Matt Snelgar  wrote:
> >
> >
> >I am making a django app to browse available products at different
> >markets.
> >I am getting data for my models from a JSON url feed,
> >
> >I am not sure on the best approach to turn this data into models as the
> >
> >feed for a single market can contain upwards of 50k items.
> >
> >
> >Models - feel free to suggest any improvements on these
> >
> ># Details of a sellable products
> >class Product(models.Model):
> >   item = models.IntegerField(primary_key=True, auto_created=False)
> >name = models.CharField(max_length=40)
> >
> ># Market where products can be bought, some markets will cater to
> >multiple suburbs.
> >class Market(models.Model):
> >id = models.IntegerField(primary_key=True, auto_created=True)
> >name = models.CharField(max_length=40)
> >
> ># Nearby suburbs can share the one market
> >class Suburb(models.Model):
> >name = models.CharField(max_length=30)
> >market = models.ForeignKey(Market, on_delete=models.SET_NULL,
> >null=True)
> >
> ># Actual product for sale
> >class ProductForSale(models.Model):
> >sale = models.IntegerField(primary_key=True)
> >product = models.ForeignKey(Product, on_delete=models.SET_NULL,
> >null=True)
> >cost = models.IntegerField(default=1)
> >owner = models.CharField(max_length=30)
> >quantity = models.IntegerField(default=1)
> >market = models.ForeignKey(Market,on_delete=models.SET_NULL, null=True
> >)
> >Feed of markets products example
> >
> >"market_products": [
> >{
> >"id":11654,
> >"item":123,
> >"owner":"Bob",
> >"suburb":"Springvale",
> >"cost":3,
> >"quantity":1,
> >
> >},
> >{
> >"id":11655,
> >"item":123,
> >"owner":"Sarah",
> >"suburb":"Sunnyville",
> >"cost":5,
> >"quantity":2,
> >
> >},
> >
> >This is how I am trying to populate my ProductForSale models - I don't
> >know
> >if this is the correct approach for the Product FK, or how to link the
> >suburb to its Market FK
> >
> >markets = Market.objects.all()
> >for market in markets:
> >url = "jsonurl"
> >response = urllib.request.urlopen(url)
> >data = json.loads(response.read())
> >for entry in data['market_products']:
> >new_product_sale = ProductForSale.objects.create(
> >product = Product.objects.get(item=entry['item']),
> >cost = entry['cost'],
> >owner = entry['owner'],
> >quantity = entry['quantity']
> >)
> >new_product_sale.save()
> >
> >Is there a point where I should create a separate model for each
> >markets
> >products, or is it fine to house them all in the one model?
>
> Do products from different markets have many different fields?  Or are
> most of the fields common?
>
> Do you need to be able to filter on products across markets? Or are most
> of your product queries specific to a particular market?
>

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


I canot upload files how can i fix it

2018-05-12 Thread carlos . davalos17
 views 

def ArticuloFormA(request,Materiaid): 
Articulos = Articulo.objects.filter(Materia_id= Materiaid) 
Articulos = Articulos.order_by('-Fecha_Publicacion')[:5] 
Pregunta_Form = ArticuloForm() 
args = {'Pregunta_Form': Pregunta_Form} 
if request.method == 'POST': 
form = ArticuloForm(request.POST or None, request.FILES or None)  
if form.is_valid(): 
Materias = Materia.objects.get(id = Materiaid) 
Preguntad = form.save(commit=False) 
Preguntad.user = request.user 
Preguntad.Texto_Pregunta = request.POST['Titulo'] 
Preguntad.Materia = Materias 
Preguntad.Pdf_articulo = request.FILES['Pdf_articulo'] 
Preguntad.save() 
return render(request,'articulos/detail.html',{'Preguntas': 
Articulos,'Materias': Materias}) 
else: 
Pregunta_Form = ArticuloForm() 
args = {'Pregunta_Form': Pregunta_Form} 
return render(request,'foro/FormPregunta.html',args) 


html

{% extends 'cuentas/base.html' %}

{% block body %}

CrearPregunta

{% csrf_token %}
{{ Pregunta_Form.docfile }}
Submit


{% endblock %}

-- 
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/353c96a5-5946-4530-beb4-71ad83c0366b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Creating models from json url feed

2018-05-12 Thread Ryan Nowakowski
I'd use a single model for all products from any market then.

On Sun, May 13, 2018 at 09:47:32AM +0800, Matt Snelgar wrote:
> All of the products will share the same fields.
> 
> I would filter on products, but my searches would only be restricted to one
> market at a time.
> 
> On Sun, May 13, 2018 at 1:51 AM, Ryan Nowakowski 
> wrote:
> 
> >
> >
> > On May 10, 2018 7:40:47 AM CDT, Matt Snelgar  wrote:
> > >
> > >
> > >I am making a django app to browse available products at different
> > >markets.
> > >I am getting data for my models from a JSON url feed,
> > >
> > >I am not sure on the best approach to turn this data into models as the
> > >
> > >feed for a single market can contain upwards of 50k items.
> > >
> > >
> > >Models - feel free to suggest any improvements on these
> > >
> > ># Details of a sellable products
> > >class Product(models.Model):
> > >   item = models.IntegerField(primary_key=True, auto_created=False)
> > >name = models.CharField(max_length=40)
> > >
> > ># Market where products can be bought, some markets will cater to
> > >multiple suburbs.
> > >class Market(models.Model):
> > >id = models.IntegerField(primary_key=True, auto_created=True)
> > >name = models.CharField(max_length=40)
> > >
> > ># Nearby suburbs can share the one market
> > >class Suburb(models.Model):
> > >name = models.CharField(max_length=30)
> > >market = models.ForeignKey(Market, on_delete=models.SET_NULL,
> > >null=True)
> > >
> > ># Actual product for sale
> > >class ProductForSale(models.Model):
> > >sale = models.IntegerField(primary_key=True)
> > >product = models.ForeignKey(Product, on_delete=models.SET_NULL,
> > >null=True)
> > >cost = models.IntegerField(default=1)
> > >owner = models.CharField(max_length=30)
> > >quantity = models.IntegerField(default=1)
> > >market = models.ForeignKey(Market,on_delete=models.SET_NULL, null=True
> > >)
> > >Feed of markets products example
> > >
> > >"market_products": [
> > >{
> > >"id":11654,
> > >"item":123,
> > >"owner":"Bob",
> > >"suburb":"Springvale",
> > >"cost":3,
> > >"quantity":1,
> > >
> > >},
> > >{
> > >"id":11655,
> > >"item":123,
> > >"owner":"Sarah",
> > >"suburb":"Sunnyville",
> > >"cost":5,
> > >"quantity":2,
> > >
> > >},
> > >
> > >This is how I am trying to populate my ProductForSale models - I don't
> > >know
> > >if this is the correct approach for the Product FK, or how to link the
> > >suburb to its Market FK
> > >
> > >markets = Market.objects.all()
> > >for market in markets:
> > >url = "jsonurl"
> > >response = urllib.request.urlopen(url)
> > >data = json.loads(response.read())
> > >for entry in data['market_products']:
> > >new_product_sale = ProductForSale.objects.create(
> > >product = Product.objects.get(item=entry['item']),
> > >cost = entry['cost'],
> > >owner = entry['owner'],
> > >quantity = entry['quantity']
> > >)
> > >new_product_sale.save()
> > >
> > >Is there a point where I should create a separate model for each
> > >markets
> > >products, or is it fine to house them all in the one model?
> >
> > Do products from different markets have many different fields?  Or are
> > most of the fields common?
> >
> > Do you need to be able to filter on products across markets? Or are most
> > of your product queries specific to a particular market?
> >

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