Using Sum() for a models method inside a Query

2014-11-23 Thread Jorge Andrés Vergara Ebratt
Hello everyone,

Well, the tittle says it all:

I have a model X

class X(models.Model)
a = models.IntegerField()
b = models.IntegerField()

def getC(self):
return a + b


So, when I'm inside a template I can call {{x.getC}} and it gets the method
for the current instance it's in, but how can I get the Sum, or Avg of that
method? I tried doing Sum('getC') but I get the error because getC isn't
callable in the query...

Thanks in advance for the help

-- 
*Jorge Andres Vergara Ebratt*
*#SoftwareDeveloper (Or at least trying to be)*
*@javebratt*
*facebook.com/javebratt *

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAeX05Gb5oV%3DkiBcAeMdQ33jcau2B_yWYXFMgJbNB4Y8QMJ5Qw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-23 Thread Russell Keith-Magee
On Sun, Nov 23, 2014 at 5:28 AM, martin f krafft 
wrote:

> Hello,
>
> we have a Django project with a few pages that come from Git.
> Currently, Apache rewrite rules serve those files statically (and
> they make use of the same template/CSS as Django does, so the user
> does not actually notice), and it's a massive hack and pain to keep
> up-to-date.
>
> Hence I was thinking: how much trouble would it be to have Django
> reach into Git rather than its database and obtain data there to be
> filled into template slots? Ideally, there'd be the possibility of
> running a filter (e.g. reStructuredText) between Git and the
> template rendering.
>
> I've seen http://luispedro.org/software/git-cms, but that does way
> more than just sourcing from Git. And it's not immediately obvious
> to me how it even does the Git interaction.
>
> What I envision is a storage layer (with optional caching) that
> either fetches from the filesystem (with a Git checkout, using mtime
> for cache expiration), or directly from a local Git repo (using
> either commit or blob hash for cache expiration).
>
> Does anyone know of such a module? Would it be hard to write? Where
> would one start?
>

The problem is that there isn't one. There's several :-)

I'm aware of at least 3:

https://pypi.python.org/pypi/GitPython/0.3.2.1
https://pypi.python.org/pypi/pygit2
https://pypi.python.org/pypi/dulwich

These are all Python wrappers around the Git API - and, in the case of
dulwich, a full re-implementation of git in Python. Using these APIs, you
should be able to retrieve an file with an arbitrary hash, the same as you
would at the command line.

I haven't used any of them myself, so I can't comment on which one is
best/most stable/most reliable/fastest, but:

 * Yes, they exist

 * Yes, you could use these modules to retrieve information from the git
checkout as part of a view

 * Yes, that data could then be passed to a template, either directly, or
after post-processing with a filter of some kind.

Yours,
Russ Magee %-)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq849yt%2BU99gWy66uGD_%2BC2%2BuKZoQ2OTAop8UWuLGa9BvOkQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using Sum() for a models method inside a Query

2014-11-23 Thread Vijay Khemlani
What do you mean by the sum or average of the method? As in the sum or
average of the method applied to a list of objects "X"?

On Sun, Nov 23, 2014 at 7:41 PM, Jorge Andrés Vergara Ebratt <
javebr...@gmail.com> wrote:

> Hello everyone,
>
> Well, the tittle says it all:
>
> I have a model X
>
> class X(models.Model)
> a = models.IntegerField()
> b = models.IntegerField()
>
> def getC(self):
> return a + b
>
>
> So, when I'm inside a template I can call {{x.getC}} and it gets the
> method for the current instance it's in, but how can I get the Sum, or Avg
> of that method? I tried doing Sum('getC') but I get the error because getC
> isn't callable in the query...
>
> Thanks in advance for the help
>
> --
> *Jorge Andres Vergara Ebratt*
> *#SoftwareDeveloper (Or at least trying to be)*
> *@javebratt*
> *facebook.com/javebratt *
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAAeX05Gb5oV%3DkiBcAeMdQ33jcau2B_yWYXFMgJbNB4Y8QMJ5Qw%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CALn3ei2Rb3j8OZ9MEKsjnB8x8xwJ_z5nLuJKja-QZpZRgGu6SA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Auto-refresh the webpage in the  browser, after modify and save

2014-11-23 Thread Jose Regalado
Greetings...

I need auto-refresh the webpage in the  browser, after modify and save any 
file of my project, views: , css, jss, .*py, etc. I have 2 monitors. 

 Exist some module or similar for django?, I am using 1.7 1.8-dev

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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/bfbde3e5-6274-4536-b257-8eb3f7e655c2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using Sum() for a models method inside a Query

2014-11-23 Thread Ethan Blackburn
related: https://groups.google.com/forum/#!topic/django-users/s9qgXC4TNrA

Short answer: you can't. A raw query would be your best bet(i.e. "SELECT 
SUM(a + b) AS sum FROM app_X")


On Sunday, November 23, 2014 4:42:48 PM UTC-6, Jorge Andrés Vergara Ebratt 
wrote:
>
> Hello everyone,
>
> Well, the tittle says it all:
>
> I have a model X
>
> class X(models.Model)
> a = models.IntegerField()
> b = models.IntegerField()
>
> def getC(self):
> return a + b
>
>
> So, when I'm inside a template I can call {{x.getC}} and it gets the 
> method for the current instance it's in, but how can I get the Sum, or Avg 
> of that method? I tried doing Sum('getC') but I get the error because getC 
> isn't callable in the query...
>
> Thanks in advance for the help
>
> -- 
> *Jorge Andres Vergara Ebratt*
> *#SoftwareDeveloper (Or at least trying to be)*
> *@javebratt*
> *facebook.com/javebratt *
>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/b5350447-264f-4145-be9d-8ea709673918%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Obtaining content from Git

2014-11-23 Thread martin f krafft
also sprach Russell Keith-Magee  [2014-11-24 00:42 
+0100]:
> The problem is that there isn't one. There's several :-)
> 
> I'm aware of at least 3:
> 
> https://pypi.python.org/pypi/GitPython/0.3.2.1
> https://pypi.python.org/pypi/pygit2
> https://pypi.python.org/pypi/dulwich

I am aware of those and I was wondering more about the glue on the
Django-side of things, i.e. how the storage plugin/layer would work.

I am pretty inexperienced with Django, hence I find it hard to even
figure out where the sensible place to do this would be.

-- 
@martinkrafft | http://madduck.net/ | http://two.sentenc.es/
 
"there are two major products that come out of berkeley: lsd and unix.
 we don't believe this to be a coincidence."
 -- jeremy s. anderson
 
spamtraps: madduck.bo...@madduck.net

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20141124054512.GA14198%40fishbowl.rw.madduck.net.
For more options, visit https://groups.google.com/d/optout.


digital_signature_gpg.asc
Description: Digital signature (see http://martin-krafft.net/gpg/sig-policy/999bbcc4/current)


Re: Obtaining content from Git

2014-11-23 Thread Russell Keith-Magee
On Mon, Nov 24, 2014 at 1:45 PM, martin f krafft 
wrote:

> also sprach Russell Keith-Magee  [2014-11-24
> 00:42 +0100]:
> > The problem is that there isn't one. There's several :-)
> >
> > I'm aware of at least 3:
> >
> > https://pypi.python.org/pypi/GitPython/0.3.2.1
> > https://pypi.python.org/pypi/pygit2
> > https://pypi.python.org/pypi/dulwich
>
> I am aware of those and I was wondering more about the glue on the
> Django-side of things, i.e. how the storage plugin/layer would work.
>
> I am pretty inexperienced with Django, hence I find it hard to even
> figure out where the sensible place to do this would be.
>

The right place is in the view.

At the simplest level, a view is just a function that converts a request
into a response. "Normal" Django template rendering (i.e., return
render(request, "mytemplate.html", {'object': obj}) ) hides a lot of detail
- but all it's really doing is opening a file on disk (from one of a couple
of a known locations - the template directories), parsing that template,
rendering it with a context, and returning it to the user.

A simple "hello world" view will develop "obj" by doing database queries -
but the information can come from any other data source that is relevant.
You might hit a non-relational store (such as Redis), or a search engine
(like ElasticSearch), or do some sort of calculation based on the GET/POST
arguments provided. In your case, you'll be taking the GET/POST values,
plus the URL parameters, and using them to identify a "resource" in your
Git tree; your git calls will extract that resource; and then you can
either return that resource literally as your response (with an appropriate
content type), or pass the resource to a template to be rendered.

Thinking about the storage layer is going deeper than you need to go. The
storage layer is an abstraction to enable reusable apps. If I write a "user
profile" app that needs to store an avatar, then I don't care where that
avatar comes from, as long as it's available. It could be on a local
filesystem; it could be on a cloud file store (like S3). The storage API
lets me do that.

The storage API isn't there to abstract all possible concepts of storage
that might exist, and just because you'll be accessing a notional file
system, doesn't mean that access needs to be done through the storage API -
it's fine to just open the file.

While you probably *could* write a storage plugin that would read a git
repository, that's not really what the storage API is for.

If you're just looking to read the *current* value in a git repository,
then just use normal filesystem storage over a normal git checkout. If you
want to do "interesting" things like retrieve a specific file version,
you're not going to be able to use the storage API, because most raw
filesystems don't have a concept of versioning.

Yours,
Russ Magee %-)

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAJxq848%2B46c7Hz1P9VCaiOoZqyoNekDGDdrH0iiDUaXUpCKcNw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


models.py question for setting up multiple sql entries for 1 master sql entry

2014-11-23 Thread Bovine Devine
Hello,

I am creating hardware database webapp in django and I have a question for 
how to setup my models.py to ensure I get the data entered into the mysql 
db that I have setup.

I have my models.py setup this way:

from django.db import models
from django.utils import timezone
# Create your models here.


class Hardwareid(models.Model):
hardwareid_text = models.CharField(max_length=200)
pub_date = models.DateField(default=timezone.now)
def __unicode__(self): 
return self.hardwareid_text
 class Barcodeid1(models.Model):
barcode1 = models.ForeignKey(Hardwareid)
Barcodeid1_text = models.CharField(max_length=50)
def __unicode__(self): 
return self.Barcodeid1_text
class Barcodeid2(models.Model):
barcode2 = models.ForeignKey(Hardwareid)
Barcodeid2_text = models.CharField(max_length=50)
def __unicode__(self): 
return self.Barcodeid2_text


My question is do I have this setup properly? The end result I would like 
to have is to have a "master" Hardwareid name of an item in my sql db that 
has multiple barcodeids associated with each master hardwareid.

Is this the correct way to do it?

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/47abd291-f46c-4d9b-b535-bd1ed0a7c6da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.