Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 368435
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T13:49:24+00:00 2026-05-12T13:49:24+00:00

I have a couple of tables that are joined by GUIDs in SQL Server.

  • 0

I have a couple of tables that are joined by GUIDs in SQL Server. Now, I’ve found a few custom fields to add support for GUIDs in django, but I tend to shy away from using code in blog posts if at all possible. I’m not going to do anything with the GUID other than join on it and maybe assign a GUID on new entries (although this is optional). Is there any way to allow this using django’s built-in types? Like can I use some kind of char field or binary field and “trick” django into joining using it?

If it’s any help, I’m using django-pyodbc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T13:49:24+00:00Added an answer on May 12, 2026 at 1:49 pm

    I’d create a basic GUID Model in order to reuse it’s properties for any other models in my projects. Model inheritance is working nicely since several versions prior to Django 1.0 and is quite stable with Django 1.0.

    Create something like project/common/models.py and place there this class:

    import hashlib
    import random
    from django.db import models
    
    class GUIDModel(models.Model):
    
        guid = models.CharField(primary_key=True, max_length=40)
    
        def save(self, *args, **kwargs):
    
          if not self.guid:
            self.guid = hashlib.sha1(str(random.random())).hexdigest()
    
          super(GUIDModel, self).save(*args, **kwargs)
    

    Then create your other models as usual:

    from common.models import GUIDModel
    
    class Customer(GUIDModel):
      name = models.CharField(max_length=64)
    
    class Product(GUIDModel):
      name = models.CharField(max_length=64)
    
    class Sale(GUIDModel):
      customer = models.ForeignKey(Customer)
      product = models.ForeignKey(Product)
      items = models.PositiveIntegerField()
    

    And everything should work nicely with GUIDs as primary keys instead of autoincremental integers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a couple of tables in a SQL 2008 server that I need
I have a couple of tables that are transaction tables, and I would like
I have a couple of tables (mySQL) that i would like to update with
I have a couple tables that are kind of unrelated - id like to
I have a XML file that I need to populate multiple SQL tables, and
We have a couple of synonyms that are being used to reference tables in
I have a couple tables that I want to keep a revision history on.
I have a select query in which I have joined a couple of tables
I have a couple of tables that are laid out like this: +------------------------------------+ +
I have a couple of tables in MySQL that I'm working with that do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.