I'd like to find how to select all objects whose ManyToMany field contains another object. I have the following models (stripped down)
class Category(models.Model):
pass
class Picture(models.Model):
categories = models.ManyToManyField(Category)
visible = models.BooleanField()
I need a function to select all the Pictures i...
I have a WSGI application that generates invoices and stores them as PDF.
So far I have solved similar problems with FPDF (or equivalents), generating the PDF from scratch like a GUI. Sadly this means the entire formatting logic (positioning headers, footers and content, styling) is in the application, where it really shouldn't be.
As ...
My Application has a lot of calculation being done in JavaScript according to how and when the user acts on the application. The project prints out valuable information (through console calls) as to how this calculation is going on, and so we can easily spot any NaNs creeping in.
We are planning to integrate Selenium (RC with python) to...
In Smalltalk there is a message DoesNotUnderstand that is called when an object does not understand a message (this is, when the object does not have the message sent implemented).
So, I like to know if in python there is a function that does the same thing.
In this example:
class MyObject:
def __init__(self):
print "MyOb...
Hi,
Is there any equivalent to str.split in Python that also returns the delimiters?
I need to preserve the whitespace layout for my output after processing some of the tokens.
Example:
>>> s="\tthis is an example"
>>> print s.split()
['this', 'is', 'an', 'example']
>>> print what_I_want(s)
['\t', 'this', ' ', 'is', ' ', 'an', ' '...
I am in the process of deploying a new Django site to replace a current Wordpress blog. As I get it setup, I want to test everything in the domain's subdirectory before I switch things to the root and "go live". For example: http://example.com/django/
Editing my .htaccess file allows me to redirect things without a hitch (I can see th...
I'm trying to write a function that reads files from a "deferred" directory which contains files that contain lists. Here's what the files in the deferred folder contain:
'173378981', '45000', '343434', '3453453', '34534545', '3452342', '234234', '42063008', 'Exempted', '10000'
'1000014833', '0', '0', '0', '0', '0', '0', '0', 'Exempted'...
Hi,
I have a django website that is spilt depending on what user type you are, I need to redirect users that are not entitled to see certain aspects of the site,
in my template, I have
{% if user.get_profile.is_store %}
<!--DO SOME LOGIC-->
{%endif%}
how would I go about redirecting said store back to the index of the site?
==...
Though there can be many but as i am very new to python so which modules or classes within standard libraries i should know when programming in python, especially when i am practicing programming challenges from a C++ book? Libraries which can make my life easier? Since there can be no single correct answer, i am making this question a w...
I can see the problem, I attached my code and error page.
In my template, I have:
{% if user.get_profile.is_store %}
<!--DO SOME LOGIC-->
{%endif%}
In my view, I have:
def downloads(request):
"""
Downloads page, a user facing page for the trade members to downloads POS etc
"""
if not authenticated_user(request):
return H...
I am working on a simulation in Queueing Theory, within a wxPython GUI. (Project link.) What would be a good tool for visualizing the simulations? The visualization should consist of simple objects, such as clients, servers, a facility and a population. They should all be represented by simple boxes or something like that. There will be ...
This is a pretty simple Django question, but I can't find the answer in the Django docs, despite lots of hunting!
How do I check whether an object already exists, and only add it if it does not already exist?
Here's the code - I don't want to add the follow_role twice in the database if it already exists. How do I check first? Use get(...
I am trying to get a unicode version of calendar.month_abbr[6]. If I don't specify an encoding for the locale, I don't know how to convert the string to unicode. The example code below shows my problem:
>>> import locale
>>> import calendar
>>> locale.setlocale(locale.LC_ALL, ("ru_RU"))
'ru_RU'
>>> print repr(calendar.month_abbr[6])
'\x...
To tag the data we create, I'm considering using uuids. Security is not an issue, so I was going to use version 1 (date-and-mac-address-based). The only concern is that each user may be creating multiple data files at once from different processes with multiple threads. Assuming Python's uuid library is thread-safe (though it doesn't ...
Consider this:
>>> a = [("one","two"), ("bad","good")]
>>> for i in a:
... for x in i:
... print x
...
one
two
bad
good
How can I write this code, but using a syntax like:
for i in a:
print [x for x in i]
Obviously, This does not work, it prints:
['one', 'two']
['bad', 'good']
I want the same output. Can it be ...
SqlAlchemy newbie question:
Base = declarative_base()
class A(Base):
__tablename__ = 'as'
id = Column(Integer, primary_key=True)
class B(Base):
__tablename__ = 'bs'
id = Column(Integer, primary_key=True)
a = relation(A)
When I create my database schema, I have two tables, as and bs, which have one column (id) but...
I am trying to make a Django website be a simple Windows executable. I've been told that py2exe does not work correctly, both due to Django using __import__, and to its attempting to dispatch manage.py in some obscure way. Is that the case? If so, is there an alternative tool that works better, or is there a way to work around the py2...
My company is switching from make to scons. Part of our make process is to call xmllint on a number of xml files to validate them against a schema.
I've got the following in my SConstruct:
import os;
Env = DefaultEnvironment()
pwd = Dir('.').path
xmlValidator = Builder(action = 'xmllint --noout --schema '+pwd+'/path/schema.xsd '+pwd+...
I am running a sub-program using subprocess.popen. When I start my Python program from the command window (cmd.exe), the program writes some info and dates in the window as the program evolves.
When I run my Python code not in a command window, it opens a new command window for this sub-program's output, and I want to avoid that. When...
I am looking to create a python script that will read one source file then produce another file with a string for the name.
for example
macaddress.cnf.xml contains the source file
I need to change '6000' to '6001' in multiple places of macaddress.cnf.xml, then I want to output to newmacaddress.cnf.xl.
This is what I have
#! /usr/...