# Use field as default for another field

**URL:** <https://forum.djangoproject.com/t/use-field-as-default-for-another-field/1114>\
**Category:** Using Django\
**Created:** [February 10, 2020, 9:04am UTC](https://forum.djangoproject.com/t/use-field-as-default-for-another-field/1114 "2020-02-10T09:04:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [February 10, 2020, 9:04am UTC](https://forum.djangoproject.com/t/use-field-as-default-for-another-field/1114/1 "2020-02-10T09:04:17Z")

</div>

I am new to Django

So I have this model for a page and it looks like this:  
from django.db import models  
from django.utils import timezone

```
# Create your models here.
class Page(models.Model):
    title = models.CharField(max_length=200, unique=True, editable=True)
    body = models.TextField(editable=True, help_text='This is the body of the page')
    url = models.CharField(max_length=128, unique=True, default=Page.title)
    date_created = models.DateTimeField(auto_now_add=True)
    published = models.BooleanField(default=True)
        
    class Meta:
       ordering = ['date_created']
       verbose_name_plural = "pages"

    def __str__ (self):
        return self.title

```

When I run the server it tells me Page in not defined. How can Page not be defined? How do I then make the Page.title the default if no URL is entered?

Help is appreciated thanks

---

<div class="post-metadata">

**Author:** ![adamchainz](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/adamchainz/32/26_2.png) [@adamchainz](https://forum.djangoproject.com/u/adamchainz)\
**Post date:** [February 10, 2020, 9:37am UTC](https://forum.djangoproject.com/t/use-field-as-default-for-another-field/1114/2 "2020-02-10T09:37:17Z")

</div>

It’s not defined since due to Python’s scoping rules. The class isn’t defined until the end of its definition.

As for filling one field with another, you can either do it in a custom `save()` for your model, or use a `SlugField` which will prefill in the admin: [https://docs.djangoproject.com/en/3.0/ref/models/fields/#slugfield](https://docs.djangoproject.com/en/3.0/ref/models/fields/#slugfield)

---

<div class="post-metadata">

**Author:** ![calvincani](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/calvincani/32/1150_2.png) [@calvincani](https://forum.djangoproject.com/u/calvincani)\
**Post date:** [February 10, 2020, 9:46am UTC](https://forum.djangoproject.com/t/use-field-as-default-for-another-field/1114/3 "2020-02-10T09:46:54Z")

</div>

Thank you I will check it out
