How to Show Calculated Field in Django Admin
Let's say I have a model Invoice.
class Invoice(models.Model):
labor_hour_quantity = models.DecimalField(max_digits=9, decimal_places=1)
labor_descrip = models.TextField(blank=True)
labor_hour_cost = models.DecimalField(max_digits=9, decimal_places=2)
Within the model I have a property defined as such.
@property
def labor_total(self):
return self.labor_hour_quantity * self.labor_hour_cost
How do I get this displayed on Django Admin when I look at an invoice I create? Currently it doesn't even display a DecimalField or value of the return after saving the invoice.
/r/django
https://redd.it/6xigr3
Let's say I have a model Invoice.
class Invoice(models.Model):
labor_hour_quantity = models.DecimalField(max_digits=9, decimal_places=1)
labor_descrip = models.TextField(blank=True)
labor_hour_cost = models.DecimalField(max_digits=9, decimal_places=2)
Within the model I have a property defined as such.
@property
def labor_total(self):
return self.labor_hour_quantity * self.labor_hour_cost
How do I get this displayed on Django Admin when I look at an invoice I create? Currently it doesn't even display a DecimalField or value of the return after saving the invoice.
/r/django
https://redd.it/6xigr3
reddit
How to Show Calculated Field in Django Admin • r/django
Let's say I have a model Invoice. class Invoice(models.Model): labor_hour_quantity = models.DecimalField(max_digits=9, ...
Flask-mail adding data to email
Hello again guys i have a invoice that im generating but in that invoice i want to add data from database how can i add that data to a template to be send as a email, i am using render_template() but how to make does values persist when that email is sent.
render_template('template.html', var='var')
In the template I'm calling
{{var}} # but it doesn't display the value of var in gmail
Thanks in advance.
/r/flask
https://redd.it/6xfvn7
Hello again guys i have a invoice that im generating but in that invoice i want to add data from database how can i add that data to a template to be send as a email, i am using render_template() but how to make does values persist when that email is sent.
render_template('template.html', var='var')
In the template I'm calling
{{var}} # but it doesn't display the value of var in gmail
Thanks in advance.
/r/flask
https://redd.it/6xfvn7
reddit
Flask-mail adding data to email • r/flask
Hello again guys i have a invoice that im generating but in that invoice i want to add data from database how can i add that data to a template to...
New to Python/Django; following the Tutorial but it seems to take issue with SQLite?
This tutorial: [Link]( https://docs.djangoproject.com/en/1.11/intro/tutorial02/ ) - I'm stuck right before "Introducing the Django Admin"
I created the database according to the instructions, and I used SQLite3 because it was recommended. I wanted MySQL, but alas, I chose SQLite, which seems to cause issues - now I believe the model/migration (?) does not contain the proper FOREIGN_KEY, so I cannot continue. How do I fix this?
manage.py sqlmigrate only shows the CREATE_TABLE commands, the foreign key was mentioned but it seems there was no constraint added alongside it, and as a result the choice_set does not exist (i.e., there's no Related Manager attached, according to Google).
Apparently constraints were disabled by default for SQLite3 (why would the tutorial recommend it and not mention that?) - but it was also supposedly fixed years ago ([Link](https://code.djangoproject.com/ticket/14204) and [Link 2](https://code.djangoproject.com/ticket/14204))
That is as far as googling got me. I have considerable programming experience, but none in Python/with Django, and so I am unable to find the solution on my own. Would anybody be willing to help?
/r/django
https://redd.it/6xg5ks
This tutorial: [Link]( https://docs.djangoproject.com/en/1.11/intro/tutorial02/ ) - I'm stuck right before "Introducing the Django Admin"
I created the database according to the instructions, and I used SQLite3 because it was recommended. I wanted MySQL, but alas, I chose SQLite, which seems to cause issues - now I believe the model/migration (?) does not contain the proper FOREIGN_KEY, so I cannot continue. How do I fix this?
manage.py sqlmigrate only shows the CREATE_TABLE commands, the foreign key was mentioned but it seems there was no constraint added alongside it, and as a result the choice_set does not exist (i.e., there's no Related Manager attached, according to Google).
Apparently constraints were disabled by default for SQLite3 (why would the tutorial recommend it and not mention that?) - but it was also supposedly fixed years ago ([Link](https://code.djangoproject.com/ticket/14204) and [Link 2](https://code.djangoproject.com/ticket/14204))
That is as far as googling got me. I have considerable programming experience, but none in Python/with Django, and so I am unable to find the solution on my own. Would anybody be willing to help?
/r/django
https://redd.it/6xg5ks
Help me understand get_object_or_404 better
Hey folks,
I have a couple of FBVs in a couple of learning projects, where I have get_object_or_404() functions, and I'd like to understand it better where it takes the argument from.
Does it always get the argument from the url pattern? I guess I think about url patterns as just a slug definer, and not as part of the core code.
This one adds a picture to a given project:
FBV:
> @login_required
def adicionar_post_ao_projeto(request, pk):
projeto = get_object_or_404(Projeto, pk=pk)
if request.method == "POST":
form = PostForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.projeto = projeto
post.user = request.user
post.save()
return redirect('posts:single', pk=post.pk)
else:
form = PostForm()
return render(request, 'post_form.html', {'form': form})
URL pattern:
> url(r"(?P<pk>\d+)/novafoto$",views.adicionar_post_ao_projeto,name="adicionar_foto_ao_projeto"),
Sorry if my logic thinking here is not clear enough.
/r/django
https://redd.it/6xf116
Hey folks,
I have a couple of FBVs in a couple of learning projects, where I have get_object_or_404() functions, and I'd like to understand it better where it takes the argument from.
Does it always get the argument from the url pattern? I guess I think about url patterns as just a slug definer, and not as part of the core code.
This one adds a picture to a given project:
FBV:
> @login_required
def adicionar_post_ao_projeto(request, pk):
projeto = get_object_or_404(Projeto, pk=pk)
if request.method == "POST":
form = PostForm(request.POST)
if form.is_valid():
post = form.save(commit=False)
post.projeto = projeto
post.user = request.user
post.save()
return redirect('posts:single', pk=post.pk)
else:
form = PostForm()
return render(request, 'post_form.html', {'form': form})
URL pattern:
> url(r"(?P<pk>\d+)/novafoto$",views.adicionar_post_ao_projeto,name="adicionar_foto_ao_projeto"),
Sorry if my logic thinking here is not clear enough.
/r/django
https://redd.it/6xf116
reddit
Help me understand get_object_or_404 better • r/django
Hey folks, I have a couple of FBVs in a couple of learning projects, where I have get_object_or_404() functions, and I'd like to understand it...
Exploiting misuse of Python's "pickle"
https://blog.nelhage.com/2011/03/exploiting-pickle/
/r/Python
https://redd.it/6xgd5a
https://blog.nelhage.com/2011/03/exploiting-pickle/
/r/Python
https://redd.it/6xgd5a
reddit
Exploiting misuse of Python's "pickle" • r/Python
168 points and 18 comments so far on reddit
Raymond Hettinger, Keynote on Concurrency, PyBay 2017
https://www.youtube.com/watch?v=9zinZmE3Ogk
/r/Python
https://redd.it/6xkvaz
https://www.youtube.com/watch?v=9zinZmE3Ogk
/r/Python
https://redd.it/6xkvaz
YouTube
Raymond Hettinger, Keynote on Concurrency, PyBay 2017
Keynote for https://pybay.com, 2nd annual Regional Python Conference in SF.
Slides: http://pybay.com/site_media/slides/raymond2017-keynote/index.html
Slides: http://pybay.com/site_media/slides/raymond2017-keynote/index.html
What is the best python implementation to optimize a lot of gridsearch iterations?
Hello,
I have a small dataset that needs to be trained using different ML algorithm. Also those algorithms need to be tuned using gridsearch. In native python running the script can take up to a day.
I need to choose the environment that will be best fit to run such a task.
What would be your suggestion? Native Python, Pyspark or some different implementation of python? Maybe splitting the tasks?
/r/Python
https://redd.it/6xkeq0
Hello,
I have a small dataset that needs to be trained using different ML algorithm. Also those algorithms need to be tuned using gridsearch. In native python running the script can take up to a day.
I need to choose the environment that will be best fit to run such a task.
What would be your suggestion? Native Python, Pyspark or some different implementation of python? Maybe splitting the tasks?
/r/Python
https://redd.it/6xkeq0
reddit
What is the best python implementation to optimize a... • r/Python
Hello, I have a small dataset that needs to be trained using different ML algorithm. Also those algorithms need to be tuned using gridsearch. In...
pyvips 1.0 released: fast, low memory use image handling for all Python runtimes
pyvips 1.0 has just been released:
https://jcupitt.github.io/libvips/2017/09/01/libvips-for-Python.html
It's a binding for the libvips image processing library. On this benchmark at least, pyvips is more than 4x faster than Pillow-SIMD and needs less than 1/4 of the memory:
https://github.com/jcupitt/libvips/wiki/Speed-and-memory-use
libvips has included a Python binding for a long time, but it's been very annoying to install and has had limited documentation.
This new binding is based on cffi, so as long as you can get the libvips shared library on to your system (via apt, yum, homebrew, or a download of the win binary), it's just "pip install pyvips". There are dynamic docs with help(), and also full on-line docs:
https://jcupitt.github.io/pyvips/
/r/Python
https://redd.it/6xldgs
pyvips 1.0 has just been released:
https://jcupitt.github.io/libvips/2017/09/01/libvips-for-Python.html
It's a binding for the libvips image processing library. On this benchmark at least, pyvips is more than 4x faster than Pillow-SIMD and needs less than 1/4 of the memory:
https://github.com/jcupitt/libvips/wiki/Speed-and-memory-use
libvips has included a Python binding for a long time, but it's been very annoying to install and has had limited documentation.
This new binding is based on cffi, so as long as you can get the libvips shared library on to your system (via apt, yum, homebrew, or a download of the win binary), it's just "pip install pyvips". There are dynamic docs with help(), and also full on-line docs:
https://jcupitt.github.io/pyvips/
/r/Python
https://redd.it/6xldgs
jcupitt.github.io
libvips for Python
A fast image processing library with low memory needs.
0–100 in Django: The Perfect Environment
https://medium.com/@jeremytiki/0-100-in-django-the-perfect-environment-a906827028fc
/r/django
https://redd.it/6xh24k
https://medium.com/@jeremytiki/0-100-in-django-the-perfect-environment-a906827028fc
/r/django
https://redd.it/6xh24k
Medium
0–100 in Django: The Perfect Environment
If you have worked with Django for any amount of time you have probably seen many articles about how to setup your development environment…
Programming Fundamentals for Data Science [xpost from datascience]
I am entering my final semester in a Data Science Master's program and just completed a three month data science internship at a large corporation. While the experience was very fulfilling, it also highlighted my lack of programming (and math!) background or experience.
I have a Bachelor's in business before I joined the program and only did simple SQL work - self taught - in my last job. I've obviously done schoolwork in Python and R, but it became apparent when the training wheels came off and I was faced with a blank screen that there was much I didn't know.
What concepts, methods, best practices are fundamental to learn to become proficient in Python/R, or better yet, give me the ability to pick up any language I may need in the future.
Thanks!
/r/Python
https://redd.it/6xn3wy
I am entering my final semester in a Data Science Master's program and just completed a three month data science internship at a large corporation. While the experience was very fulfilling, it also highlighted my lack of programming (and math!) background or experience.
I have a Bachelor's in business before I joined the program and only did simple SQL work - self taught - in my last job. I've obviously done schoolwork in Python and R, but it became apparent when the training wheels came off and I was faced with a blank screen that there was much I didn't know.
What concepts, methods, best practices are fundamental to learn to become proficient in Python/R, or better yet, give me the ability to pick up any language I may need in the future.
Thanks!
/r/Python
https://redd.it/6xn3wy
reddit
Programming Fundamentals for Data Science [xpost from... • r/Python
I am entering my final semester in a Data Science Master's program and just completed a three month data science internship at a large...
Is there an extension like Flask-Admin, but for the user to use?
So If I have a web application with users, and they have a lot of data in databases is there an extension out there to make displaying all this data to them easier than building out tables in html and passing the data through?
/r/flask
https://redd.it/6x2txp
So If I have a web application with users, and they have a lot of data in databases is there an extension out there to make displaying all this data to them easier than building out tables in html and passing the data through?
/r/flask
https://redd.it/6x2txp
reddit
Is there an extension like Flask-Admin, but for the user... • r/flask
So If I have a web application with users, and they have a lot of data in databases is there an extension out there to make displaying all this...
Hunter 2.0 - can now trace other processes
Just made a release (https://pypi.python.org/pypi/hunter#changelog) with a process tracing feature. It works in two ways:
* GDB injection. Like all the other projects, it's prone to the same kinds of problems, deadlocks, segfaults and whatnot. But for development I guess it's ok ...
* Bootstrapping via [manhole](https://pypi.python.org/pypi/manhole). A convenience `hunter.remote.install()` is provided.
Give it a try, eg `pip install -U 'hunter[remote]'` and `hunter-trace -p PID --gdb`.
Also, it has filters, eg: `hunter-trace -p PID stdlib=False`.
Windows ain't supported. If you have ideas for Windows support let me know.
PS. Yes, I don't know how to reddit.
/r/Python
https://redd.it/6xpcxx
Just made a release (https://pypi.python.org/pypi/hunter#changelog) with a process tracing feature. It works in two ways:
* GDB injection. Like all the other projects, it's prone to the same kinds of problems, deadlocks, segfaults and whatnot. But for development I guess it's ok ...
* Bootstrapping via [manhole](https://pypi.python.org/pypi/manhole). A convenience `hunter.remote.install()` is provided.
Give it a try, eg `pip install -U 'hunter[remote]'` and `hunter-trace -p PID --gdb`.
Also, it has filters, eg: `hunter-trace -p PID stdlib=False`.
Windows ain't supported. If you have ideas for Windows support let me know.
PS. Yes, I don't know how to reddit.
/r/Python
https://redd.it/6xpcxx
pypi.python.org
hunter 2.0.2 : Python Package Index
Hunter is a flexible code tracing toolkit.
What I'm Currently Working On
https://github.com/PyPiPie/Scarlet-1.0-Virtual-Assistant-Made-With-Python
/r/Python
https://redd.it/6xpomj
https://github.com/PyPiPie/Scarlet-1.0-Virtual-Assistant-Made-With-Python
/r/Python
https://redd.it/6xpomj
GitHub
PyPiPie/Scarlet-1.0-Virtual-Assistant-Made-With-Python
Scarlet-1.0-Virtual-Assistant-Made-With-Python - S.C.A.R.L.E.T (Sorta Crappy Assistant Robot Lazily Engineered Today) To be honest making up that acronym was easier than making this virtual assista...
[AF] Beginner Question: "object is not callable" from inside a route
Having this problem that I can't figure out what is wrong with it.
[Link to pastebin of code](https://pastebin.com/xykEQ3qG)
I must be not understanding some fundamental aspect of all of python to not being able to understand it.
edit:
here is the error code: *TypeError: 'Test' object is not callable*
/r/flask
https://redd.it/6wr1i9
Having this problem that I can't figure out what is wrong with it.
[Link to pastebin of code](https://pastebin.com/xykEQ3qG)
I must be not understanding some fundamental aspect of all of python to not being able to understand it.
edit:
here is the error code: *TypeError: 'Test' object is not callable*
/r/flask
https://redd.it/6wr1i9
Pastebin
[Python] Python-Flask Object is not callable - Pastebin.com
syntax error when following the official tutorial!
I've gotten [this](https://docs.djangoproject.com/en/1.11/intro/tutorial02/#playing-with-the-api) far into the official tutorail for Django, but I keep getting an error when getting to the filter function.
Here's the command I tried to run, and its consequent output:
>>> Question.objects.filter(id=1)
File "<console>", line 1
Question.objects.filter(id=1)
^
SyntaxError: invalid syntax
What have I done wrong? I've been sure to import the models and that doens't return any errors.
Here's my models.py: https://gist.github.com/wOstensen/d55c63135df9da9c99a61e80a7a7aeee
EDIT: Running on Windows 10 with Python 3.6.0 in Cygwin.
/r/djangolearning
https://redd.it/6xlw4j
I've gotten [this](https://docs.djangoproject.com/en/1.11/intro/tutorial02/#playing-with-the-api) far into the official tutorail for Django, but I keep getting an error when getting to the filter function.
Here's the command I tried to run, and its consequent output:
>>> Question.objects.filter(id=1)
File "<console>", line 1
Question.objects.filter(id=1)
^
SyntaxError: invalid syntax
What have I done wrong? I've been sure to import the models and that doens't return any errors.
Here's my models.py: https://gist.github.com/wOstensen/d55c63135df9da9c99a61e80a7a7aeee
EDIT: Running on Windows 10 with Python 3.6.0 in Cygwin.
/r/djangolearning
https://redd.it/6xlw4j
Gist
models.py
Best Practices: OOP in Python.
I sure this question is nothing new but I want to hear your answers anyways. I am actually new to object-oriented programming (even though I know the theoretical concepts; OOP has a lot of resemblance in pure math, particularly in set theory).
What are some best practices in creating OOP systems in Python? And what are some bad practices to avoid?
Throughout my programming experience, I spent most of my time organizing my programs into functions/definitions, not necessarily relying much on classes. But I think OOP, as a paradigm, is pretty good for implementing mathematical structures.
/r/Python
https://redd.it/6xs6od
I sure this question is nothing new but I want to hear your answers anyways. I am actually new to object-oriented programming (even though I know the theoretical concepts; OOP has a lot of resemblance in pure math, particularly in set theory).
What are some best practices in creating OOP systems in Python? And what are some bad practices to avoid?
Throughout my programming experience, I spent most of my time organizing my programs into functions/definitions, not necessarily relying much on classes. But I think OOP, as a paradigm, is pretty good for implementing mathematical structures.
/r/Python
https://redd.it/6xs6od
reddit
Best Practices: OOP in Python. • r/Python
I sure this question is nothing new but I want to hear your answers anyways. I am actually new to object-oriented programming (even though I know...
How to count choices in aggregation?
suppose we have a model of a document:
class Document(TitleDescriptionModel, TimeStampedModel):
...
source = models.ForeignKey(Source, related_name='docs', blank=True, null=True)
class Meta:
ordering = ('year', 'month', 'title' )
and its source:
class Source(models.Model):
PHOTO = 'photo'
NEWSPAPER = 'newspaper'
MAGAZINE = 'magazine'
BOOK = 'book'
OTHER = 'other'
...
kind = models.CharField(max_length=32, choices=TYPE_CHOICES, default=PHOTO)
class Meta:
ordering = ('title', 'id', )
how to get how many photos, newspapers and magazines are in db?
the only solution i know is to use standard Counter:
qs = Document.objects.values_list('source__kind', flat=True)
counter = Counter(qs)
Counter({'other': 123,
'newspaper': 234,
'magazine': 345,
'book': 456,
'photo': 567,
None: 111})
i tried to do the same with `aggregate` but in vain. how could it be done?
/r/django
https://redd.it/6xrodm
suppose we have a model of a document:
class Document(TitleDescriptionModel, TimeStampedModel):
...
source = models.ForeignKey(Source, related_name='docs', blank=True, null=True)
class Meta:
ordering = ('year', 'month', 'title' )
and its source:
class Source(models.Model):
PHOTO = 'photo'
NEWSPAPER = 'newspaper'
MAGAZINE = 'magazine'
BOOK = 'book'
OTHER = 'other'
...
kind = models.CharField(max_length=32, choices=TYPE_CHOICES, default=PHOTO)
class Meta:
ordering = ('title', 'id', )
how to get how many photos, newspapers and magazines are in db?
the only solution i know is to use standard Counter:
qs = Document.objects.values_list('source__kind', flat=True)
counter = Counter(qs)
Counter({'other': 123,
'newspaper': 234,
'magazine': 345,
'book': 456,
'photo': 567,
None: 111})
i tried to do the same with `aggregate` but in vain. how could it be done?
/r/django
https://redd.it/6xrodm
reddit
How to count choices in aggregation? • r/django
suppose we have a model of a document: class Document(TitleDescriptionModel, TimeStampedModel): ... source =...