Search Results

Search found 4129 results on 166 pages for 'models'.

Page 1/166 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Where is meta.local_fields set in django.db.models.base.py ?

    - by BryanWheelock
    I'm getting the error: Exception Value: (1110, "Column 'about' specified twice") As I was reviewing the Django error page, I noticed that the customizations the model User, seem to be appended to the List twice. This seems to be happening here in django/db/model/base.py in base_save(): values = [(f, f.get_db_prep_save(raw and getattr(self, f.attname) or f.pre_save(self, True))) for f in meta.local_fields] this is what Django error page shows values to be: values = [(<django.db.models.fields.CharField object at 0xa78996c>, u'kallie'), (<django.db.models.fields.CharField object at 0xa7899cc>, ''), (<django.db.models.fields.CharField object at 0xa789a2c>, ''), (<django.db.models.fields.EmailField object at 0xa789a8c>, u'[email protected]'), (<django.db.models.fields.CharField object at 0xa789b2c>, 'sha1$d4a80$0e5xxxxxxxxxxxxxxxxxxxxddadfb07'), (<django.db.models.fields.BooleanField object at 0xa789bcc>, False), (<django.db.models.fields.BooleanField object at 0xa789c6c>, True), (<django.db.models.fields.BooleanField object at 0xa789d2c>, False), (<django.db.models.fields.DateTimeField object at 0xa789dcc>, u'2010-02-03 14:54:35'), (<django.db.models.fields.DateTimeField object at 0xa789e2c>, u'2010-02-03 14:54:35'), # this is where the values from the User model customizations show up (<django.db.models.fields.BooleanField object at 0xa8c69ac>, False), (<django.db.models.fields.CharField object at 0xa8c688c>, None), (<django.db.models.fields.PositiveIntegerField object at 0xa8c69cc>, 1), (<django.db.models.fields.CharField object at 0xa8c69ec>, 'b5ab1603b2308xxxxxxxxxxx75bca1'), (<django.db.models.fields.SmallIntegerField object at 0xa8c6dac>, 0), (<django.db.models.fields.SmallIntegerField object at 0xa8c6e4c>, 0), (<django.db.models.fields.SmallIntegerField object at 0xa8c6e8c>, 0), (<django.db.models.fields.SmallIntegerField object at 0xa8c6ecc>, 10), (<django.db.models.fields.DateTimeField object at 0xa8c6eec>, u'2010-02-03 14:54:35'), (<django.db.models.fields.CharField object at 0xa8c6f2c>, ''), (<django.db.models.fields.URLField object at 0xa8c6f6c>, ''), (<django.db.models.fields.CharField object at 0xa8c6fac>, ''), (<django.db.models.fields.DateField object at 0xa8c6fec>, None), (<django.db.models.fields.TextField object at 0xa8cb04c>, ''), # at this point User model customizations repeats itself (<django.db.models.fields.BooleanField object at 0xa663b0c>, False), (<django.db.models.fields.CharField object at 0xaa1e94c>, None), (<django.db.models.fields.PositiveIntegerField object at 0xaa1e34c>, 1), (<django.db.models.fields.CharField object at 0xaa1e40c>, 'b5ab1603b2308050ebd62f49ca75bca1'), (<django.db.models.fields.SmallIntegerField object at 0xa8c6d8c>, 0), (<django.db.models.fields.SmallIntegerField object at 0xaa2378c>, 0), (<django.db.models.fields.SmallIntegerField object at 0xaa237ac>, 0), (<django.db.models.fields.SmallIntegerField object at 0xaa237ec>, 10), (<django.db.models.fields.DateTimeField object at 0xaa2380c>, u'2010-02-03 14:54:35'), (<django.db.models.fields.CharField object at 0xaa2384c>, ''), (<django.db.models.fields.URLField object at 0xaa2388c>, ''), (<django.db.models.fields.CharField object at 0xaa238cc>, ''), (<django.db.models.fields.DateField object at 0xaa2390c>, None), (<django.db.models.fields.TextField object at 0xaa2394c>, '')] Since this app is in Production, I can't figure out how to use pdb.set_trace() to see what's going on inside of save_base. The customizations to User are: User.add_to_class('email_isvalid', models.BooleanField(default=False)) User.add_to_class('email_key', models.CharField(max_length=16, null=True)) User.add_to_class('reputation', models.PositiveIntegerField(default=1)) User.add_to_class('gravatar', models.CharField(max_length=32)) User.add_to_class('email_feeds', generic.GenericRelation(EmailFeed)) User.add_to_class('favorite_questions', models.ManyToManyField(Question, through=FavoriteQuestion, related_name='favorited_by')) User.add_to_class('badges', models.ManyToManyField(Badge, through=Award, related_name='awarded_to')) User.add_to_class('gold', models.SmallIntegerField(default=0)) User.add_to_class('silver', models.SmallIntegerField(default=0)) User.add_to_class('bronze', models.SmallIntegerField(default=0)) User.add_to_class('questions_per_page', models.SmallIntegerField(choices=QUESTIONS_PER_PAGE_CHOICES, default=10)) User.add_to_class('last_seen', models.DateTimeField(default=datetime.datetime.now)) User.add_to_class('real_name', models.CharField(max_length=100, blank=True)) User.add_to_class('website', models.URLField(max_length=200, blank=True)) User.add_to_class('location', models.CharField(max_length=100, blank=True)) User.add_to_class('date_of_birth', models.DateField(null=True, blank=True)) User.add_to_class('about', models.TextField(blank=True)) Django1.1.1 Python 2.5

    Read the article

  • Django models: Use multiple values as a key?

    - by Rosarch
    Here is a simple model: class TakingCourse(models.Model): course = models.ForeignKey(Course) term = models.ForeignKey(Term) Instead of Django creating a default primary key, I would like to use both course and term as the primary key - taken together, they uniquely identify a tuple. Is this allowed by Django? On a related note: I am trying to represent users taking courses in certain terms. Is there a better way to do this? class Course(models.Model): name = models.CharField(max_length=200) requiredFor = models.ManyToManyField(RequirementSubSet, blank=True) offeringSchool = models.ForeignKey(School) def __unicode__(self): return "%s at %s" % (self.name, self.offeringSchool) class MyUser(models.Model): user = models.ForeignKey(User, unique=True) takingReqSets = models.ManyToManyField(RequirementSet, blank=True) takingTerms = models.ManyToManyField(Term, blank=True) takingCourses = models.ManyToManyField(TakingCourse, blank=True) school = models.ForeignKey(School) class TakingCourse(models.Model): course = models.ForeignKey(Course) term = models.ForeignKey(Term) class Term(models.Model): school = models.ForeignKey(School) isPrimaryTerm = models.BooleanField()

    Read the article

  • Populating Models from other Models in Django?

    - by JT
    This is somewhat related to the question posed in this question but I'm trying to do this with an abstract base class. For the purposes of this example lets use these models: class Comic(models.Model): name = models.CharField(max_length=20) desc = models.CharField(max_length=100) volume = models.IntegerField() ... <50 other things that make up a Comic> class Meta: abstract = True class InkedComic(Comic): lines = models.IntegerField() class ColoredComic(Comic): colored = models.BooleanField(default=False) In the view lets say we get a reference to an InkedComic id since the tracer, err I mean, inker is done drawing the lines and it's time to add color. Once the view has added all the color we want to save a ColoredComic to the db. Obviously we could do inked = InkedComic.object.get(pk=ink_id) colored = ColoredComic() colored.name = inked.name etc, etc. But really it'd be nice to do: colored = ColoredComic(inked_comic=inked) colored.colored = True colored.save() I tried to do class ColoredComic(Comic): colored = models.BooleanField(default=False) def __init__(self, inked_comic = False, *args, **kwargs): super(ColoredComic, self).__init__(*args, **kwargs) if inked_comic: self.__dict__.update(inked_comic.__dict__) self.__dict__.update({'id': None}) # Remove pk field value but it turns out the ColoredComic.objects.get(pk=1) call sticks the pk into the inked_comic keyword, which is obviously not intended. (and actually results in a int does not have a dict exception) My brain is fried at this point, am I missing something obvious, or is there a better way to do this?

    Read the article

  • Show models.ManyToManyField as inline, with the same form as models.ForeignKey inline

    - by Kristian
    I have a model similar to the following (simplified): models.py class Sample(models.Model): name=models.CharField(max_length=200) class Action(models.Model): samples=models.ManyToManyField(Sample) title=models.CharField(max_length=200) description=models.TextField() Now, if Action.samples would have been a ForeignKey instead of a ManyToManyField, when I display Action as a TabularInline in Sample in the Django Admin, I would get a number of rows, each containing a nice form to edit or add another Action. However; when I display the above as an inline using the following: class ActionInline(admin.TabularInline): model=Action.samples.through I get a select box listing all available actions, and not a nifty form to create a new Action. My question is really: How do I display the ManyToMany relation as an inline with a form to input information as described? In principle it should be possible since, from the Sample's point of view, the situation is identical in both cases; Each Sample has a list of Actions regardless if the relation is a ForeignKey or a ManyToManyRelation. Also; Through the Sample admin page, I never want to choose from existing Actions, only create new or edit old ones.

    Read the article

  • How to convert this query to a "django model query" ?

    - by fabriciols
    Hello ! What i want is simple : models : class userLastTrophy(models.Model): user = models.ForeignKey(userInfo) platinum = models.IntegerField() gold = models.IntegerField() silver = models.IntegerField() bronze = models.IntegerField() level = models.IntegerField() rank = models.IntegerField() perc_level = models.IntegerField() date_update = models.DateTimeField(default=datetime.now, blank=True) total = models.IntegerField() points = models.IntegerField() class userTrophy(models.Model): user = models.ForeignKey(userInfo) platinum = models.IntegerField() gold = models.IntegerField() silver = models.IntegerField() bronze = models.IntegerField() total = models.IntegerField() level = models.IntegerField() perc_level = models.IntegerField() date_update = models.DateTimeField(default=datetime.now, blank=True) rank = models.IntegerField(default=0) total = models.IntegerField(default=0) points = models.IntegerField(default=0) last_trophy = models.ForeignKey(userLastTrophy, default=0) I have this query : select t2.user_id as id, t2.platinum - t1.platinum as plat, t2.gold - t1.gold as gold, t2.silver - t1.silver as silver, t2.bronze - t1.bronze as bronze, t2.points - t1.points as points from myps3t_usertrophy t2, myps3t_userlasttrophy t1 where t1.id = t2.last_trophy_id order by points; how to do this with django models ?

    Read the article

  • ModelName(django.contrib.auth.models.User) vs ModelName(models.Model)

    - by amr.negm
    I am developing a django project. I created some apps, some of those are related to User model, for instance, I have a feeds app that handles user feeds, and another app that deals with extra user data like age, contacts, and friends. for each of these, I created a table that should be connected to the User model, which I using for storing and authenticating users. I found two ways to deal with this issue. One, is through extending User model to be like this: ModelName(User): friends = models.ManyToMany('self') ..... Two, is through adding a foreign key to the new table like this: ModelName(models.Model): user = models.ForeignKey(User, unique=True) friends = friends = models.ManyToMany('self') ...... I can't decide which to use in which case. in other words, what are the core differences between both?

    Read the article

  • Models with more than one mesh in JMonkeyEngine

    - by Andrea Tucci
    I’m a new jmonkey engine developer and I’m beginning to import models. I tried to import simple models and no problems appeared, but when I export some obj models having more than one mesh in the OgreXML format, Blender saves multiple meshes with their own materials (e.g. one mesh for face, another for body etc). Can I export all the meshes in one? I’ve tried to join all the meshes to a major one with blender (face joins body), but when I export the model and then create the Spatial in jme(loading the path of the “merged” mesh), all the meshes that are joined to the major doesn’t have their materials! I give a more clear example: I have an .obj model with 3 meshes and I export it. I have : mesh1.mesh.xml , mesh2.mesh.xml , mesh3.mesh.xml and their materials mesh1.material, mesh2.material mesh3.material so I import the folder in Assets/Models/Test and now I have to create something like: Spatial head = assetManager.loadModel( [path] ); Spatial face = assetManager.loadModel( [path] ) one for each mesh and than attach them to a common node. I think there is a way to merge those mesh maintaining their materials! What do you think? Thanks

    Read the article

  • Free Models and Related Animations for AI project in Unity [on hold]

    - by zhed
    Does anybody know a good website where to find free models and animations for AI projects? I'm not talking about anything good looking, like stuff you would look for when building a proper game, but, for example, a bunch of male/female models that are able to walk around and that would substitute my ugly "capsules", just to give a better -yet, still rough - idea of what's going on in the scene. On the Unity Asset Store there are a bunch of nice male/female models, but i haven't found any free general-purpose(i.e. normal walking) animation attachable to them. Any tip would we appreciated, thanks :)

    Read the article

  • django: How to make one form from multiple models containing foreignkeys

    - by Tim
    I am trying to make a form on one page that uses multiple models. The models reference each other. I am having trouble getting the form to validate because I cant figure out how to get the id of two of the models used in the form into the form to validate it. I used a hidden key in the template but I cant figure out how to make it work in the views My code is below: views: def the_view(request, a_id,): if request.method == 'POST': b_form= BForm(request.POST) c_form =CForm(request.POST) print "post" if b_form.is_valid() and c_form.is_valid(): print "valid" b_form.save() c_form.save() return HttpResponseRedirect(reverse('myproj.pro.views.this_page')) else: b_form= BForm() c_form = CForm() b_ide = B.objects.get(pk=request.b_id) id_of_a = A.objects.get(pk=a_id) return render_to_response('myproj/a/c.html', {'b_form':b_form, 'c_form':c_form, 'id_of_a':id_of_a, 'b_id':b_ide }) models class A(models.Model): name = models.CharField(max_length=256, null=True, blank=True) classe = models.CharField(max_length=256, null=True, blank=True) def __str__(self): return self.name class B(models.Model): aid = models.ForeignKey(A, null=True, blank=True) number = models.IntegerField(max_length=1000) other_number = models.IntegerField(max_length=1000) class C(models.Model): bid = models.ForeignKey(B, null=False, blank=False) field_name = models.CharField(max_length=15) field_value = models.CharField(max_length=256, null=True, blank=True) forms from mappamundi.mappa.models import A, B, C class BForm(forms.ModelForm): class Meta: model = B exclude = ('aid',) class CForm(forms.ModelForm): class Meta: model = C exclude = ('bid',) B has a foreign key reference to A, C has a foreign key reference to B. Since the models are related, I want to have the forms for them on one page, 1 submit button. Since I need to fill out fields for the forms for B and C & I dont want to select the id of B from a drop down list, I need to somehow get the id of the B form into the form so it will validate. I have a hidden field in the template, I just need to figure how to do it in the views

    Read the article

  • Car brands and models licensing

    - by Ju-v
    We are small team which working on car racing game but we don't know about licensing process for branded cars like Nissan, Lamborghini, Chevrolet and etc. Do we need to buy any licence for using real car brand names, models, logos,... or we can use them for free? Second option we think about using not real brand with real models is it possible? If someone have experience with that, fell free to share it. Any information about that is welcome.

    Read the article

  • 3D models overlapping each other

    - by Auren
    I have a problem at the moment when I draw some models to teach me more about 3D game programming. The models at the moment overlaps each other from some angles witch makes sense since the game at the moment draws from left to right, line after line. However my question is: Is there any easy escape from this issue or is there any way that you could draw the in-game world from the players position? I would really appreciate if someone could give me some answers on this.

    Read the article

  • Testing Django Inline ModelForms: How to arrange POST data?

    - by unclaimedbaggage
    Hi folks, I have a Django 'add business' view which adds a new business with an inline 'business_contact' form. The form works fine, but I'm wondering how to write up the unit test - specifically, the 'postdata' to send to self.client.post(settings.BUSINESS_ADD_URL, postdata) I've inspected the fields in my browser and tried adding post data with corresponding names, but I still get a 'ManagementForm data is missing or has been tampered with' error when run. Anyone know of any resources for figuring out how to post inline data? Relevant models, views & forms below if it helps. Lotsa thanks. MODEL: class Contact(models.Model): """ Contact details for the representatives of each business """ first_name = models.CharField(max_length=200) surname = models.CharField(max_length=200) business = models.ForeignKey('Business') slug = models.SlugField(max_length=150, unique=True, help_text=settings.SLUG_HELPER_TEXT) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) phone = models.CharField(max_length=100, null=True, blank=True) mobile_phone = models.CharField(max_length=100, null=True, blank=True) email = models.EmailField(null=True) deleted = models.BooleanField(default=False) class Meta: db_table='business_contact' def __unicode__(self): return '%s %s' % (self.first_name, self.surname) @models.permalink def get_absolute_url(self): return('business_contact', (), {'contact_slug': self.slug }) class Business(models.Model): """ The business clients who you are selling products/services to """ business = models.CharField(max_length=255, unique=True) slug = models.SlugField(max_length=100, unique=True, help_text=settings.SLUG_HELPER_TEXT) description = models.TextField(null=True, blank=True) primary_contact = models.ForeignKey('Contact', null=True, blank=True, related_name='primary_contact') business_type = models.ForeignKey('BusinessType') deleted = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) address_1 = models.CharField(max_length=255, null=True, blank=True) address_2 = models.CharField(max_length=255, null=True, blank=True) suburb = models.CharField(max_length=255, null=True, blank=True) city = models.CharField(max_length=255, null=True, blank=True) state = models.CharField(max_length=255, null=True, blank=True) country = models.CharField(max_length=255, null=True, blank=True) phone = models.CharField(max_length=40, null=True, blank=True) website = models.URLField(null=True, blank=True) class Meta: db_table = 'business' def __unicode__(self): return self.business def get_absolute_url(self): return '%s%s/' % (settings.BUSINESS_URL, self.slug) VIEWS: class Contact(models.Model): """ Contact details for the representatives of each business """ first_name = models.CharField(max_length=200) surname = models.CharField(max_length=200) business = models.ForeignKey('Business') slug = models.SlugField(max_length=150, unique=True, help_text=settings.SLUG_HELPER_TEXT) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) phone = models.CharField(max_length=100, null=True, blank=True) mobile_phone = models.CharField(max_length=100, null=True, blank=True) email = models.EmailField(null=True) deleted = models.BooleanField(default=False) class Meta: db_table='business_contact' def __unicode__(self): return '%s %s' % (self.first_name, self.surname) @models.permalink def get_absolute_url(self): return('business_contact', (), {'contact_slug': self.slug }) class Business(models.Model): """ The business clients who you are selling products/services to """ business = models.CharField(max_length=255, unique=True) slug = models.SlugField(max_length=100, unique=True, help_text=settings.SLUG_HELPER_TEXT) description = models.TextField(null=True, blank=True) primary_contact = models.ForeignKey('Contact', null=True, blank=True, related_name='primary_contact') business_type = models.ForeignKey('BusinessType') deleted = models.BooleanField(default=False) created = models.DateTimeField(auto_now_add=True) updated = models.DateTimeField(auto_now=True) address_1 = models.CharField(max_length=255, null=True, blank=True) address_2 = models.CharField(max_length=255, null=True, blank=True) suburb = models.CharField(max_length=255, null=True, blank=True) city = models.CharField(max_length=255, null=True, blank=True) state = models.CharField(max_length=255, null=True, blank=True) country = models.CharField(max_length=255, null=True, blank=True) phone = models.CharField(max_length=40, null=True, blank=True) website = models.URLField(null=True, blank=True) class Meta: db_table = 'business' def __unicode__(self): return self.business def get_absolute_url(self): return '%s%s/' % (settings.BUSINESS_URL, self.slug) FORMS: class AddBusinessForm(ModelForm): class Meta: model = Business exclude = ['deleted','primary_contact',] class ContactForm(ModelForm): class Meta: model = Contact exclude = ['deleted',] AddBusinessFormSet = inlineformset_factory(Business, Contact, can_delete=False, extra=1, form=AddBusinessForm, )

    Read the article

  • How to use mount points in MilkShape models?

    - by vividos
    I have bought the Warriors & Commoners model pack from Frogames and the pack contains (among other formats) two animated models and several non-animated objects (axe, shield, pilosities, etc.) in MilkShape3D format. I looked at the official "MilkShape 3D Viewer v2.0" (msViewer2.zip at http://www.chumba.ch/chumbalum-soft/ms3d/download.html) source code and implemented loading the model, calculating the joint matrices and everything looks fine. In the model there are several joints that are designated as the "mount points" for the static objects like axe and shield. I now want to "put" the axe into the hand of the animated model, and I couldn't quite figure out how. I put the animated vertices in a VBO that gets updated every frame (I know I should do this with a shader, but I didn't have time to do this yet). I put the static vertices in another VBO that I want to keep static and not updated every frame. I now tried to render the animated vertices first, then use the joint matrix for the "mount joint" to calculate the location of the static object. I tried many things, and what about seems to be right is to transpose the joint matrix, then use glMatrixMult() to transform the modelview matrix. For some objects like the axe this is working, but not for others, e.g. the pilosities. Now my question: How is this generally implemented when using bone/joint models, and especially with MilkShape3D models? Am I on the right track?

    Read the article

  • Applying prerecorded animations to models with the same skeleton

    - by Jeremias Pflaumbaum
    well my question sounds a bit like, how do I apply mo-cap animations to my model, but thats not really it I guess. Animations and model share the same skeleton, but the models vary in size and proportion, but I still want to be able to apply any animation to any model. I think this should be possible since the models got the same skeleton bone structure and the bones are always in the same area only their position varies from model to model. In particular Im trying to apply this to 2D characters that got 2arm, 2legs, a head and a body, but if you got anything related to that topic even if its 3D related or keywords, articles, books whatever Im gratefull for everything cause Im a bit stuck at the moment. cheers Jery

    Read the article

  • django deleting models and overriding delete method

    - by Mike
    I have 2 models class Vhost(models.Model): dns = models.ForeignKey(DNS) user = models.ForeignKey(User) extra = models.TextField() class ApplicationInstalled(models.Model): user = models.ForeignKey(User) added = models.DateTimeField(auto_now_add=True) app = models.ForeignKey(Application) ver = models.ForeignKey(ApplicationVersion) vhost = models.ForeignKey(Vhost) path = models.CharField(max_length=100, default="/") def delete(self): # # remove the files # print "need to remove some files" super(ApplicationInstalled, self).delete() If I do the following >>> vhost = Vhost.objects.get(id=10) >>> vhost.id 10L >>> ApplicationInstalled.objects.filter(vhost=vhost) [<ApplicationInstalled: http://wiki.jy.com/>] >>> vhost.delete() >>> ApplicationInstalled.objects.filter(vhost=vhost) [] As you can see there is an applicationinstalled object linked to vhost but when I delete the vhost, the applicationinstalled object is gone but the print never gets called. Any easy way to do this without iterating through the objects in the vhost delete?

    Read the article

  • ContentType Issue -- Human is an idiot - Can't figure out how to tie the original model to a Content

    - by bmelton
    Originally started here: http://stackoverflow.com/questions/2650181/django-in-query-as-a-string-result-invalid-literal-for-int-with-base-10 I have a number of apps within my site, currently working with a simple "Blog" app. I have developed a 'Favorite' app, easily enough, that leverages the ContentType framework in Django to allow me to have a 'favorite' of any type... trying to go the other way, however, I don't know what I'm doing, and can't find any examples for. I'll start off with the favorite model: favorite/models.py from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic from django.contrib.auth.models import User class Favorite(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() user = models.ForeignKey(User) content_object = generic.GenericForeignKey() class Admin: list_display = ('key', 'id', 'user') class Meta: unique_together = ("content_type", "object_id", "user") Now, that allows me to loop through the favorites (on a user's "favorites" page, for example) and get the associated blog objects via {{ favorite.content_object.title }}. What I want now, and can't figure out, is what I need to do to the blog model to allow me to have some tether to the favorite (so when it is displayed in a list it can be highlighted, for example). Here is the blog model: blog/models.py from django.db import models from django.db.models import permalink from django.template.defaultfilters import slugify from category.models import Category from section.models import Section from favorite.models import Favorite from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic class Blog(models.Model): title = models.CharField(max_length=200, unique=True) slug = models.SlugField(max_length=140, editable=False) author = models.ForeignKey(User) homepage = models.URLField() feed = models.URLField() description = models.TextField() page_views = models.IntegerField(null=True, blank=True, default=0 ) created_on = models.DateTimeField(auto_now_add = True) updated_on = models.DateTimeField(auto_now = True) def __unicode__(self): return self.title @models.permalink def get_absolute_url(self): return ('blog.views.show', [str(self.slug)]) def save(self, *args, **kwargs): if not self.slug: slug = slugify(self.title) duplicate_count = Blog.objects.filter(slug__startswith = slug).count() if duplicate_count: slug = slug + str(duplicate_count) self.slug = slug super(Blog, self).save(*args, **kwargs) class Entry(models.Model): blog = models.ForeignKey('Blog') title = models.CharField(max_length=200) slug = models.SlugField(max_length=140, editable=False) description = models.TextField() url = models.URLField(unique=True) image = models.URLField(blank=True, null=True) created_on = models.DateTimeField(auto_now_add = True) def __unicode__(self): return self.title def save(self, *args, **kwargs): if not self.slug: slug = slugify(self.title) duplicate_count = Entry.objects.filter(slug__startswith = slug).count() if duplicate_count: slug = slug + str(duplicate_count) self.slug = slug super(Entry, self).save(*args, **kwargs) class Meta: verbose_name = "Entry" verbose_name_plural = "Entries" Any guidance?

    Read the article

  • How to create instances of related models in Django

    - by sevennineteen
    I'm working on a CMSy app for which I've implemented a set of models which allow for creation of custom Template instances, made up of a number of Fields and tied to a specific Customer. The end-goal is that one or more templates with a set of custom fields can be defined through the Admin interface and associated to a customer, so that customer can then create content objects in the format prescribed by the template. I seem to have gotten this hooked up such that I can create any number of Template objects, but I'm struggling with how to create instances - actual content objects - in those templates. For example, I can define a template "Basic Page" for customer "Acme" which has the fields "Title" and "Body", but I haven't figured out how to create Basic Page instances where these fields can be filled in. Here are my (somewhat elided) models... class Customer(models.Model): ... class Field(models.Model): ... class Template(models.Model): label = models.CharField(max_length=255) clients = models.ManyToManyField(Customer, blank=True) fields = models.ManyToManyField(Field, blank=True) class ContentObject(models.Model): label = models.CharField(max_length=255) template = models.ForeignKey(Template) author = models.ForeignKey(User) customer = models.ForeignKey(Customer) mod_date = models.DateTimeField('Modified Date', editable=False) def __unicode__(self): return '%s (%s)' % (self.label, self.template) def save(self): self.mod_date = datetime.datetime.now() super(ContentObject, self).save() Thanks in advance for any advice!

    Read the article

  • Importing Models from Maya to OpenGL

    - by Mert Toka
    I am looking for ways to import models to my game project. I am using Maya as modelling software, and GLUT for windowing of my game. I found this great parser, it imports all the textures and normal vectors, but it is compatible with .obj files of 3dsMAX. I tried to use it with Maya obj's, and it turned out that Maya's obj files are a bit different from former one, thus it cannot parse them. If you know any way to convert Maya obj files to 3dsMax obj files, that would be acceptable as well as a new parser for Maya obj files.

    Read the article

  • Consistency of DirectX models

    - by marc wellman
    Is there a way to check the consistency of a DirectX model (.x) ? Whilst compiling .x files with XNA GameStudio 3.1 compilation is aborted with the following error message: Error 2 Could not read the X file. The file is corrupt or invalid. Error code: D3DXFERR_PARSEERROR. C:\WFP\Browser\Content\m.x KiviBrowser Some models compile correctly without any error/warning and some abort as described. The files of each model have several thousand lines. I am creating the files in Googles SketchUp 8 where they all look fine and don't show any sign of corruption. Suppose I have such a model my XNA compiler won't compile because their is an inconsistency somewhere in the file - how could I identify this in order to correct it ?

    Read the article

  • Trouble exporting Maya models to Panda3D?

    - by Aerovistae
    Having issues here. I added the Panda3D exporter script thing to Maya. 2 things: When I go to export to a .egg, no .egg is formed. Instead a fileToBeExported_temp.mb appears next to the original fileToBeExported.ma. My models use curving meshes with many subdivisions, easily in the thousands, like on the smoothed tentacles of an octopus. Will Panda be able to handle this in the first place? I can't find out on my own since it won't export.

    Read the article

  • django models objects filter

    - by ha22109
    Hello All, I have a model 'Test' ,in which i have 2 foreignkey models.py class Test(models.Model): id =models.Autofield(primary_key=True) name=models.ForeignKey(model2) login=models.ForeignKey(model1) status=models.CharField(max_length=200) class model1(models.Model): id=models.CharField(primary_key=True) . . is_active=models.IntergerField() class model2(model.Model): id=models.ForeignKey(model1) . . status=model.CharField(max_length=200) When i add object in model 'Test' , if i select certain login then only the objects related to that objects(model2) should be shown in field 'name'.How can i achieve this.THis will be runtime as if i change the login field value the objects in name should also change.

    Read the article

  • Query multiple models with one value

    - by swoei
    I have multiple models which all have a FK to the same model. All I know is the FK how can I determine which of the models has the FK attached? Below an example to clearify: class ModelA(models.Model): title = models.CharField("title", max_length=80) class ModelB(models.Model): fk = models.ForeignKey(ModelA) class ModelC(models.Model): fk = models.ForeignKey(ModelA) How can I figure out without using a try/except on each model whether B or C has the FK? (The FK can only be in one of them, for the record in this case I only added two models but in the real world app there are multiple possible x amount of models which have the FK to modelA)

    Read the article

  • Child transforms problem when loading 3DS models using assimp

    - by MhdSyrwan
    I'm trying to load a textured 3d model into my scene using assimp model loader. The problem is that child meshes are not situated correctly (they don't have the correct transformations). In brief: all the mTansform matrices are identity matrices, why would that be? I'm using this code to render the model: void recursive_render (const struct aiScene *sc, const struct aiNode* nd, float scale) { unsigned int i; unsigned int n=0, t; aiMatrix4x4 m = nd->mTransformation; m.Scaling(aiVector3D(scale, scale, scale), m); // update transform m.Transpose(); glPushMatrix(); glMultMatrixf((float*)&m); // draw all meshes assigned to this node for (; n < nd->mNumMeshes; ++n) { const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]]; apply_material(sc->mMaterials[mesh->mMaterialIndex]); if (mesh->HasBones()){ printf("model has bones"); abort(); } if(mesh->mNormals == NULL) { glDisable(GL_LIGHTING); } else { glEnable(GL_LIGHTING); } if(mesh->mColors[0] != NULL) { glEnable(GL_COLOR_MATERIAL); } else { glDisable(GL_COLOR_MATERIAL); } for (t = 0; t < mesh->mNumFaces; ++t) { const struct aiFace* face = &mesh->mFaces[t]; GLenum face_mode; switch(face->mNumIndices) { case 1: face_mode = GL_POINTS; break; case 2: face_mode = GL_LINES; break; case 3: face_mode = GL_TRIANGLES; break; default: face_mode = GL_POLYGON; break; } glBegin(face_mode); for(i = 0; i < face->mNumIndices; i++)// go through all vertices in face { int vertexIndex = face->mIndices[i];// get group index for current index if(mesh->mColors[0] != NULL) Color4f(&mesh->mColors[0][vertexIndex]); if(mesh->mNormals != NULL) if(mesh->HasTextureCoords(0))//HasTextureCoords(texture_coordinates_set) { glTexCoord2f(mesh->mTextureCoords[0][vertexIndex].x, 1 - mesh->mTextureCoords[0][vertexIndex].y); //mTextureCoords[channel][vertex] } glNormal3fv(&mesh->mNormals[vertexIndex].x); glVertex3fv(&mesh->mVertices[vertexIndex].x); } glEnd(); } } // draw all children for (n = 0; n < nd->mNumChildren; ++n) { recursive_render(sc, nd->mChildren[n], scale); } glPopMatrix(); } What's the problem in my code ? I've added some code to abort the program if there's any bone in the meshes, but the program doesn't abort, this means : no bones, is that normal? if (mesh->HasBones()){ printf("model has bones"); abort(); } Note: I am using openGL & SFML & assimp

    Read the article

  • Dajano admin site foreign key fields

    - by user292652
    hi i have the following models setup class Player(models.Model): #slug = models.slugField(max_length=200) Player_Name = models.CharField(max_length=100) Nick = models.CharField(max_length=100, blank=True) Jersy_Number = models.IntegerField() Team_id = models.ForeignKey('Team') Postion_Choices = ( ('M', 'Manager'), ('P', 'Player'), ) Poistion = models.CharField(max_length=1, blank=True, choices =Postion_Choices) Red_card = models.IntegerField( blank=True, null=True) Yellow_card = models.IntegerField(blank=True, null=True) Points = models.IntegerField(blank=True, null=True) #Pic = models.ImageField(upload_to=path/for/upload, height_field=height, width_field=width, max_length=100) class PlayerAdmin(admin.ModelAdmin): list_display = ('Player_Name',) search_fields = ['Player_Name',] admin.site.register(Player, PlayerAdmin) class Team(models.Model): """Model docstring""" #slug = models.slugField(max_length=200) Team_Name = models.CharField(max_length=100,) College = models.CharField(max_length=100,) Win = models.IntegerField(blank=True, null=True) Loss = models.IntegerField(blank=True, null=True) Draw = models.IntegerField(blank=True, null=True) #logo = models.ImageField(upload_to=path/for/upload, height_field=height, width_field=width, max_length=100) class Meta: pass #def __unicode__(self): # return Team_Name #def save(self, force_insert=False, force_update=False): # pass @models.permalink def get_absolute_url(self): return ('view_or_url_name') class TeamAdmin(admin.ModelAdmin): list_display = ('Team_Name',) search_fields = ['Team_Name',] admin.site.register(Team, TeamAdmin) my question is how do i get to the admin site to show Team_name in the add player form Team_ID field currently it is only showing up as Team object in the combo box

    Read the article

  • Why can't I use __getattr__ with Django models?

    - by Joshmaker
    I've seen examples online of people using __getattr__ with Django models, but whenever I try I get errors. (Django 1.2.3) I don't have any problems when I am using __getattr__ on normal objects. For example: class Post(object): def __getattr__(self, name): return 42 Works just fine... >>> from blog.models import Post >>> p = Post() >>> p.random 42 Now when I try it with a Django model: from django.db import models class Post(models.Model): def __getattr__(self, name): return 42 And test it on on the interpreter: >>> from blog.models import Post >>> p = Post() ERROR: An unexpected error occurred while tokenizing input The following traceback may be corrupted or invalid The error message is: ('EOF in multi-line statement', (6, 0)) --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /Users/josh/project/ in () /Users/josh/project/lib/python2.6/site-packages/django/db/models/base.pyc in init(self, *args, **kwargs) 338 if kwargs: 339 raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0]) -- 340 signals.post_init.send(sender=self.class, instance=self) 341 342 def repr(self): /Users/josh/project/lib/python2.6/site-packages/django/dispatch/dispatcher.pyc in send(self, sender, **named) 160 161 for receiver in self._live_receivers(_make_id(sender)): -- 162 response = receiver(signal=self, sender=sender, **named) 163 responses.append((receiver, response)) 164 return responses /Users/josh/project/python2.6/site-packages/photologue/models.pyc in add_methods(sender, instance, signal, *args, **kwargs) 728 """ 729 if hasattr(instance, 'add_accessor_methods'): -- 730 instance.add_accessor_methods() 731 732 # connect the add_accessor_methods function to the post_init signal TypeError: 'int' object is not callable Can someone explain what is going on? EDIT: I may have been too abstract in the examples, here is some code that is closer to what I actually would use on the website: class Post(models.Model): title = models.CharField(max_length=255) slug = models.SlugField() date_published = models.DateTimeField() content = RichTextField('Content', blank=True, null=True) # Etc... Class CuratedPost(models.Model): post = models.ForeignKey('Post') position = models.PositiveSmallIntegerField() def __getattr__(self, name): ''' If the user tries to access a property of the CuratedPost, return the property of the Post instead... ''' return self.post.name # Etc... While I could create a property for each attribute of the Post class, that would lead to a lot of code duplication. Further more, that would mean anytime I add or edit a attribute of the Post class I would have to remember to make the same change to the CuratedPost class, which seems like a recipe for code rot.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >